あなたのコードで間違って何か、MagicalRecordを使用して
// this is data model, not Persistent Store URL
NSURL *storeURL = [[NSBundle bundleWithIdentifier:@"bundleid"] URLForResource:@"model" withExtension:@"momd"];
[MagicalRecord setupCoreDataStackWithStoreAtURL:storeURL]; // expect persistent store url
があり、初期化が
、本当に簡単です
// which will collect and merge all data models in the main bundle
[MagicalRecord setupCoreDataStackWithStoreNamed:@"my.sqlite"]
MagicalRecordInternal.mには、次のようなインスピレーションのコードがあります。
// *modelClass* can be any class in your dynamic framework
+ (void) setDefaultModelFromClass:(Class)modelClass;
{
NSBundle *bundle = [NSBundle bundleForClass:modelClass];
NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]];
[NSManagedObjectModel MR_setDefaultManagedObjectModel:model];
}
詳細、
あなたはcoreDataと "TMP" という名前の新しいスウィフトプロジェクトを作成する場合は、あなたがAppDelegate.swiftでこのようなものが表示されます。
lazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
let modelURL = NSBundle.mainBundle().URLForResource("tmp", withExtension: "momd")!
return NSManagedObjectModel(contentsOfURL: modelURL)!
}()
tmp.momd
という名前のファイルはありません。 Xcodeで作成されたものはtmp.xcdatamodeld
です。適切な方法はNSManagedObjectModel.mergedModelFromBundles(_:)
であり、xx.momdという名前の適切なコンパイル済みデータモデルをすべて検索します。
詳細が必要です。あなたは、単にアプリケーションからフレームワークにSQLファイルの名前を渡さないでください? – trojanfoe
基本的には、私は主なアプリにモデルをコピーするときに動作するようになっています。それ以外の場合は開くことができません。 – user281300
私はそれがなぜそのように見えません。ダイナミックライブラリは、アプリケーションと同じアドレス空間にあり、サンドボックスの権利などを共有しています。 – trojanfoe