Cocapods安装后脚本错误

时间:2018-08-29 05:28:21

标签: ios swift cocoapods

由于错误,我需要向项目中添加post_install脚本:

  

注意:编译为Swift 3.3.2,'ActiveLabel'编译为Swift 4.1.2(受支持,但可能会暴露其他编译器问题)

我从GitHub添加了建议的解决方案:

post_install do |installer| 
    installer.pods_project.targets.each do |target| 
        if target.name == 'ActiveLabel' target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.1' end end end end

我的Podfile看起来:

target 'Name' do
    use_frameworks!
    common_dependencies()

post_install do |installer| 
    installer.pods_project.targets.each do |target| 
        if target.name == 'ActiveLabel' target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.1' end end end

end

控制台出现错误:

  

[!]无效的Podfile文件:语法错误,意外的tIDENTIFIER,期望keyword_then或';'或'\ n'   ... et.name =='ActiveLabel'target.build_configurations。每个...   ... ^。

此语法有什么问题? common_dependencies只是初始化所有pod。

3 个答案:

答案 0 :(得分:0)

尝试一下。希望这能解决您的问题

 target 'Name' do
        use_frameworks!
        common_dependencies()
    end # this end is missing in your code

    post_install do |installer| 
        installer.pods_project.targets.each do |target| 
            if target.name == 'ActiveLabel' 
                target.build_configurations.each do |config|
                    config.build_settings['SWIFT_VERSION'] = '4.1' 
                end 
            end 
        end
    end

答案 1 :(得分:0)

我认为您在这里缺少Pod安装部分。

您的podfile应该看起来像这样:

target 'Name' do
    use_frameworks!
    common_dependencies()

    pod 'ActiveLabel'

end

post_install do |installer| 
  installer.pods_project.targets.each do |target| 
    if target.name == 'ActiveLabel' target.build_configurations.each do |config| 
      config.build_settings['SWIFT_VERSION'] = '4.1' 
    end 
  end 
end

希望这会有所帮助。

答案 2 :(得分:0)

“ ActiveLabel”的替代解决方案。 使用UITextView作为标签,例如:

class UIDataDetectorLabel: UITextView {

    override func awakeFromNib() {
        super.awakeFromNib()

        self.isEditable = false
        self.dataDetectorTypes = UIDataDetectorTypes.all;
        self.isScrollEnabled = false
    }
}

使用此类:

@IBOutlet weak var labelDescription: UIDataDetectorLabel!

self.labelDescription.attributedText = "here Attributted text here which contain phone, email..."

enter image description here