【问题标题】:Interface Builder broken on Framework projects using Cocoapods 1.0Interface Builder 在使用 Cocoapods 1.0 的框架项目上被破坏
【发布时间】:2016-06-30 18:06:10
【问题描述】:

迁移到 Cocoapods 1.0 后,我使用自定义 IBDesignable 的 XIB 或 Storyboard 都无法在动态框架项目上正确呈现。它失败并出现如下错误:

file:///Users/xxxxx/workspace/FooFramework/FooFramework/View.xib: error: IB Designables: Failed to update auto layout status: dlopen(FooFramework.framework, 1): Library not loaded: @rpath/Alamofire.framework/Alamofire
  Referenced from: FooFramework.framework
  Reason: image not found

file:///Users/xxxxx/workspace/FooFramework/FooFramework/View.xib: error: IB Designables: Failed to render instance of CustomView: dlopen(FooFramework.framework, 1): Library not loaded: @rpath/Alamofire.framework/Alamofire
  Referenced from: FooFramework.framework
  Reason: image not found

重现步骤:

  1. 创建一个新的 iOS 框架项目。
  2. 创建任何依赖项并将其添加到Podfile 文件。例如:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target 'FooFramework' do
pod 'Alamofire'
end
  1. 执行pod install并打开.xcworkspace文件。
  2. 创建自定义 IBDesignable UIView 子类。例如:
import UIKit

@IBDesignable class CustomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        layer.cornerRadius = 10
    }

    required init?(coder aDecoder: NSCoder)
    {
        super.init(coder: aDecoder)
        layer.cornerRadius = 10
    }
}
  1. 创建新的 XIB 或 Storyboard 并添加自定义视图。

此时 XCode 将重新编译代码并且将无法呈现自定义视图。给出上面提到的错误。


但是,工程编译正确,创建的XIB在执行时成功显示在模拟器中。它只会在 Interface Builder 的渲染时间上失败。

使用 Cocoapods 0.38 或可执行项目的相同过程按预期工作,没有获得错误,并且自定义视图正确呈现。

我是否缺少Podfile 中的任何配置参数?它是 Cocoapods 的错误吗?有什么解决办法吗?


更新

尝试使用不同的Runpath Search PathsInstallation Directory,如herehere 所述,但没有成功。

找到了使用 Cocoapods 0.39 的解决方法,仍然可以正常工作:

pod _0.39.0_ install

【问题讨论】:

    标签: ios xcode interface-builder cocoapods


    【解决方案1】:

    由于 Interface Builder 和 Playgrounds 不支持默认范围,似乎 a bug in Cocoapods

    在修复之前找到解决方法:

    1. 使用 pod _0.39.0_ install 回落到 0.39。
    2. 将以下代码添加到Podfile 的末尾:
    post_install do |installer|
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR'
            end
        end
    end

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多