gpt4 book ai didi

iphone - 关闭我的应用程序 (OSX) 后继续收到 "This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation."

转载 作者:行者123 更新时间:2023-12-03 16:02:14 25 4
gpt4 key购买 nike

我已经检查了互联网和 stackOverflow 上的几篇文章,但到目前为止找不到答案。这是我的 AppDelegate,据我所知,这些实现非常标准。我刚刚添加了以下行并传递了参数,但没有帮助..

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

我清理了我的项目,但这也没有帮助。此外,不会创建 ApplicationSupport 文件夹。有没有可能这就是问题的原因?我没有使用“使用核心数据”选项创建应用程序,但我提供了必要的方法......

-(NSPersistentStoreCoordinator *)persistentStoreCoordinator{...} 位于底部!

非常感谢您的帮助!

#import "WebLogClientAppDelegate.h"

// create anonymous catergories for uses in this class
@interface WebLogClientAppDelegate();
@property(nonatomic, readonly) NSString *applicationSupportFolder;
@property(nonatomic, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@end

@implementation WebLogClientAppDelegate
@synthesize autorPrefFeld, benutzerPrefFeld, passwortPrefFeld, hauptfenster,
managedObjectModel, managedObjectContext, autor;

- (void) applicationWillFinishLaunching:(NSNotification *)notification
{
NSLog(@"applicationWillFinishLaunching");
NSDictionary *defaultsDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Mathias Mustermann", @"autor",
@"mathias", @"benutzer",
@"passwort",@"passwort", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDict];
}

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
[moc commitEditing];
if ([moc hasChanges]) {
NSLog(@"Save needed!");
[moc save:nil];
}
return NSTerminateNow;
}

- (NSString *)autor{
return [[NSUserDefaults standardUserDefaults] stringForKey:@"autor"];
}

- (void)windowDidBecomeKey:(NSNotification *)notification
{
NSLog(@"windowDidBecomeKey");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[autorPrefFeld setStringValue:[defaults stringForKey:@"autor"]];
[benutzerPrefFeld setStringValue:[defaults stringForKey:@"benutzer"]];
[passwortPrefFeld setStringValue:[defaults stringForKey:@"passwort"]];
}

- (void)windowDidResignKey:(NSNotification *)notification
{
NSLog(@"windowDidResignKey");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[autorPrefFeld stringValue] forKey:@"autor"];
[defaults setObject:[benutzerPrefFeld stringValue] forKey:@"benutzer"];
[defaults setObject:[passwortPrefFeld stringValue] forKey:@"passwort"];
[defaults synchronize];
}

- (NSManagedObjectModel *)managedObjectModel
{
if(objectModel){
return objectModel;
}
objectModel= [NSManagedObjectModel mergedModelFromBundles:nil];
return objectModel;
}

- (NSString *)applicationSupportFolder
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
return [basePath stringByAppendingPathComponent:@"WeblogClient"];
}

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

NSFileManager *fileManager;
NSString *applicationSupportFolder;
NSURL *url;

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

fileManager = [NSFileManager defaultManager];
applicationSupportFolder = self.applicationSupportFolder;
if (![fileManager fileExistsAtPath:applicationSupportFolder]) {
[fileManager createDirectoryAtPath:applicationSupportFolder withIntermediateDirectories:NO attributes:nil error:nil];
}
url = [NSURL fileURLWithPath:[applicationSupportFolder stringByAppendingPathComponent:@"WeblogClient.xml"]];
storeCoord = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];
[storeCoord addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:options error:nil];
return storeCoord;
}



- (NSManagedObjectContext *)managedObjectContext
{
if (moc) {
return moc;
}
NSPersistentStoreCoordinator *coordinator = self.persistentStoreCoordinator;
if (coordinator) {
moc = [NSManagedObjectContext new];
[moc setPersistentStoreCoordinator:coordinator];
}
return moc;
}

@end

最佳答案

不确定您是否修复了错误,但请查看:I keep on getting "save operation failure" after any change on my XCode Data Model

对我来说,我与我正在开发的另一个项目具有相同的存储 sqlite 名称,并且已经运行了...

关于iphone - 关闭我的应用程序 (OSX) 后继续收到 "This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6948509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com