一旦你掌握了语法,我就会转向 CoreData,它非常快速且非常简单。最大的区别是您将 sql 语句替换为以下内容:
// Retrieve the entity from the local store -- much like a table in a database
NSEntityDescription *entity = [NSEntityDescription entityForName:@"AppSettings" inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
// Set the predicate -- much like a WHERE statement in a SQL database
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"version == %@", @"Default"];
[request setPredicate:predicate];
// Set the sorting -- mandatory, even if you're fetching a single record/object
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"version" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
sortDescriptors = nil;
sortDescriptor = nil;
// Request the data -- NOTE, this assumes only one match, that
// yourIdentifyingQualifier is unique. It just grabs the first object in the array.
AppSettings *appSettings1 =[[managedObjectContext executeFetchRequest:request error:&error] objectAtIndex:0];
request = nil;
//Update the object
appSettings1.backGroundImage = [NSNumber numberWithInt: backGroundGraphics.selectedSegmentIndex];
希望这对开发人员部分下的 MAC 应用商店也有帮助,真正帮助 Core Data Editor 一直是一种用途。
您始终可以直接使用 SQL,但数据存储结构与 Core Data 字段看起来有点滑稽。