【问题标题】:Invalid `Podfile` file: uninitialized constant无效的“Podfile”文件:未初始化的常量
【发布时间】:2017-10-18 17:28:00
【问题描述】:

向每个目标添加相同的 pod 是多余的。

   def RedundantPod

        pod "Pod"
    end

    target 'targetOne' do
        RedundantPod
    end

    target 'targetTwo' do
        RedundantPod
    end

以下设置会引发类型错误:[ ! ] Invalid Podfile file: uninitialized constant。这里有什么问题?

【问题讨论】:

    标签: ios cocoapods rename uninitialized-constant


    【解决方案1】:

    对于未来的读者,问题来自命名RedundantPod,它不应该以大写R开头。

    确实,以大写字母开头的名称在 Ruby 中是常量。仍然可以为方法使用常量名称,但是如果没有括号,您将无法调用它,因为解释器将查找名称作为常量。

    您需要显式调用该方法:

    def RedundantPod
       pod "Pod"
    end
    
    target 'targetOne' do
       RedundantPod()
    end
    

    或不大写重命名:

    def redundantPod
       pod "Pod"
    end
    
    target 'targetOne' do
       redundantPod
    end
    

    【讨论】:

    • 这真的很烦人,感谢@Amaury 的解决方案,它对我有用
    猜你喜欢
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 2013-11-24
    • 2015-01-19
    • 2015-06-24
    • 2016-11-14
    • 2011-12-17
    相关资源
    最近更新 更多