我的Xcode版本是6.1,而教程使用较旧版本.
当需要为Mac命令行创建一个新项目时,教程说“将类型更改为”Core Data“”,但在我的Xcode中,没有这样的Core Data选项.
那么,我该如何启动这个“核心数据”命令行项目呢?
解决方法 我正在做同样的事情,完全相同的问题.我的解决方案是启动一个新的可可项目,它将为您提供一个使用Core Data的复选框.这将生成所有Core Data Stack访问gubbins.除非所有工作都在AppDelegate.m中完成,否则实现相当直接. main()函数由applicationDIDFinishLaunching :()..方法替换.唯一需要的改变是
(NSManagedobjectModel *)managedobjectModel { // The managed object model for the application. It is a Fatal error for the application not to be able to find and load its model. if (_managedobjectModel) { return _managedobjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"FailedBankCD" withExtension:@"momd"]; _managedobjectModel = [[NSManagedobjectModel alloc] initWithContentsOfURL:modelURL]; return _managedobjectModel;}
和
(voID)applicationDIDFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application NSManagedobjectContext *context = self.managedobjectContext; NSError *error = nil; if (![context save:&error]) { NSLog(@"darn... %@",error); exit(1); } NSError* err = nil; Nsstring* dataPath = [[NSBundle mainBundle] pathForResource:@"Banks" ofType:@"Json"]; NSArray* Banks = [NSJsONSerialization JsONObjectWithData:[NSData dataWithContentsOffile:dataPath] options:kNilOptions error:&err];// NSLog(@"imported Banks: %@",Banks); NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @"mm/dd/yy"; [Banks enumerateObjectsUsingBlock:^(ID obj,NSUInteger IDx,BOol *stop) { FailedBankInfo *FailedBankInfo = [NSEntityDescription insertNewObjectForEntityForname:@"FailedBankInfo" inManagedobjectContext:context]; FailedBankInfo.name = [obj objectForKey:@"name"]; FailedBankInfo.city = [obj objectForKey:@"city"]; FailedBankInfo.state = [obj objectForKey:@"state"]; FailedBankDetails *FailedBankDetails = [NSEntityDescription insertNewObjectForEntityForname:@"FailedBankDetails" inManagedobjectContext:context];// FailedBankDetails.closeDate = [NSDate dateWithString:[obj objectForKey:@"closeDate"]]; //deprecated in yosemite FailedBankDetails.closeDate = [dateFormatter dateFromString:[obj objectForKey:@"closeDate"]]; FailedBankDetails.updateDate = [NSDate date]; FailedBankDetails.zip = [obj objectForKey:@"zip"]; FailedBankDetails.info = FailedBankInfo; FailedBankInfo.details = FailedBankDetails; NSError *error; if (![context save:&error]) { NSLog(@"darn... %@",[error localizedDescription]); } }]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForname:@"FailedBankInfo" inManagedobjectContext:context]; [fetchRequest setEntity:entity]; NSArray *fetchedobjects = [context executeFetchRequest:fetchRequest error:&error]; for (FailedBankInfo *info in fetchedobjects) { NSLog(@"name: %@",info.name); FailedBankDetails *details = info.details; NSLog(@"Zip: %@",details.zip); }}
祝你好运……
编辑1:获取教程继续进行更改的sqlite数据库 if(![coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:nil error:& error]){至 if(![coordinator addPersistentStoreWithType:NSsqliteStoreType configuration:nil URL:url options:nil error:& error]){
总结以上是内存溢出为你收集整理的核心数据 – Xcode 6.1 Mac OS X命令行工具的新项目全部内容,希望文章能够帮你解决核心数据 – Xcode 6.1 Mac OS X命令行工具的新项目所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)