Objective c 尝试在测试中添加NSPersistentStore(SQLite)时出错
我正在尝试向核心数据应用程序添加一些测试。该应用程序实际上运行良好,当我尝试创建堆栈时,测试失败得很惨 我在尝试将Objective c 尝试在测试中添加NSPersistentStore(SQLite)时出错,objective-c,cocoa-touch,core-data,tdd,nspersistentstore,Objective C,Cocoa Touch,Core Data,Tdd,Nspersistentstore,我正在尝试向核心数据应用程序添加一些测试。该应用程序实际上运行良好,当我尝试创建堆栈时,测试失败得很惨 我在尝试将SQLite类型的NSPersistentStore添加到nspersistentstorecordinator时出错: - (NSPersistentStoreCoordinator *)storeCoordinator { if (_storeCoordinator == nil) { _storeCoordinator = [[NSPersistentS
SQLite
类型的NSPersistentStore
添加到nspersistentstorecordinator
时出错:
- (NSPersistentStoreCoordinator *)storeCoordinator
{
if (_storeCoordinator == nil) {
_storeCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.model];
NSError *err = nil;
if (![_storeCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:self.dbURL
options:[[self class] persistentStoreCordinatorOptions]
error:&err]) {
//This is where I get the error
NSNotification *note = [NSNotification
notificationWithName:[[self class] persistentStoreCoordinatorErrorNotificationName]
object:self
userInfo:@{@"error" : err}];
[[NSNotificationCenter defaultCenter] postNotification:note];
NSLog(@"Error while adding a Store: %@", err);
return nil;
}
}
return _storeCoordinator;
}
这就是错误:
CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/cfisher/Library/Developer/CoreSimulator/Devices/860C8F97-354D-4A9D-B1E9-CC018680F487/data/Library/Caches/TestModel options:{
NSInferMappingModelAutomaticallyOption = 1;
NSMigratePersistentStoresAutomaticallyOption = 1;
NSReadOnlyPersistentStoreOption = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" with userInfo dictionary {
}
错误中提到的URL是通过以下方式获得的(下面的dbURL属性):
这只发生在测试中。该应用程序运行良好。有什么想法吗?在您的设置方法中,您正在使用self.testModelName进行设置之前,请检查这是否是问题所在。您可能还需要在testModelName的末尾包含
.sqlite
。
- (void)setUp {
[super setUp];
NSURL *cache = [[[NSFileManager defaultManager]
URLsForDirectory:NSCachesDirectory
inDomains:NSUserDomainMask] lastObject];
self.dbURL = [cache URLByAppendingPathComponent:self.testModelName];
self.testModelName = @"TestModel";
self.testBundle = [NSBundle bundleForClass:[self class]];
}