0

Hello i have created a Simple Application with Core Data and OS X 10.8, it's the simple template that xcode create, but if i change the Base SDK to 10.7 xcode give me this error on this method in App Controller:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (_persistentStoreCoordinator) {
    return _persistentStoreCoordinator;
}

NSManagedObjectModel *mom = [self managedObjectModel];
if (!mom) {
    NSLog(@"%@:%@ No model to generate a store from", [self class], NSStringFromSelector(_cmd));
    return nil;
}

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *applicationFilesDirectory = [self applicationFilesDirectory];
NSError *error = nil;

NSDictionary *properties = [applicationFilesDirectory resourceValuesForKeys:@[NSURLIsDirectoryKey] error:&error];

if (!properties) {
    BOOL ok = NO;
    if ([error code] == NSFileReadNoSuchFileError) {
        ok = [fileManager createDirectoryAtPath:[applicationFilesDirectory path] withIntermediateDirectories:YES attributes:nil error:&error];
    }
    if (!ok) {
        [[NSApplication sharedApplication] presentError:error];
        return nil;
    }
} else {
    if (![properties[NSURLIsDirectoryKey] boolValue]) {
        // Customize and localize this error.
        NSString *failureDescription = [NSString stringWithFormat:@"Expected a folder to store application data, found a file (%@).", [applicationFilesDirectory path]];

        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue:failureDescription forKey:NSLocalizedDescriptionKey];
        error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:101 userInfo:dict];

        [[NSApplication sharedApplication] presentError:error];
        return nil;
    }
}

NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"SimpleApp.storedata"];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
if (![coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:nil error:&error]) {
    [[NSApplication sharedApplication] presentError:error];
    return nil;
}
_persistentStoreCoordinator = coordinator;

return _persistentStoreCoordinator;
}

i receive this error:

enter image description here

how i can do?

4

1 回答 1

2

这实际上不是 Core Data 的问题,但这与对象下标有关。为了使这些文字正常工作,您的 SDK 至少需要为 OS X 10.8 或 iOS 6。

如果没有其他方法,您仍然可以使用下标并将您的 SDK 保持在 10.7,方法是向 NSObject 上实现所需方法的类别添加存根标头。你可以在这里看到一个这样的例子。不过,我建议您将 SDK 保持在 10.8 上。

于 2012-10-28T23:18:27.407 回答