2

ココアポッドであるフレームワークを作成しました。フレームワークはコアデータを使用し、ポッドの仕様には次のものがあります。

s.resource_bundles = {
  'FrameworkModel' => ['Model/**/*.xcdatamodeld']
  }

フレームワークワークスペースの別のターゲットであるデモアプリではすべて正常に動作しますが、ポッドとしてインストールすると

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSFetchRequest could not locate an NSEntityDescription for entity name 'EntityName''

何を試すべきかよくわかりませんが、データモデルファイルのモジュール名を変更しても効果はありませんでした。(私は、フレームワーク プロジェクトの名前から「現在の製品モジュール」に行き、戻ってきました。

ワークスペースのポッド プロジェクトにデータ モデル ファイルが表示されます。

4

1 に答える 1

0

私の問題は、ポッド コンシューマとして存在しないバンドルの URL から作成していたコア データ スタック、具体的にはマネージド オブジェクト モデルをどのように作成したかによって引き起こされたので、バンドルがワークスペースにある場合 (デモ アプリの場合)、またはポッド ファイルで定義されたリソース バンドルの名前で存在する場合は、次のように使用できます。

fileprivate lazy var managedObjectModel: NSManagedObjectModel = {

// the moc's model should be accessible via apps in this workspace
// or through the module that cocoapods will create as part of the file's
// resource bundle, as such, we need to look in two different places
// to use the correct bundle at run time
var rawBundle: Bundle? {

    if let bundle = Bundle(identifier: "com.thefredelement.Framework") {
        return bundle
    }

    guard
        let resourceBundleURL = Bundle(for: type(of: self)).url(forResource: "FrameworkModel", withExtension: "bundle"),
        let realBundle = Bundle(url: resourceBundleURL) else {
            return nil
    }

    return realBundle
}

guard let bundle = rawBundle else {
    print("Could not get bundle that contains the model ")
    return NSManagedObjectModel()
}

guard
    let modelURL = bundle.url(forResource: self.model, withExtension: "momd"),
    let model = NSManagedObjectModel(contentsOf: modelURL) else {
        print("Could not get bundle for managed object model")
        return NSManagedObjectModel()
}

return model
}()
于 2017-01-11T18:50:00.620 に答える