Iphone CoreData对象更新问题

Iphone CoreData对象更新问题,iphone,objective-c,ipad,core-data,Iphone,Objective C,Ipad,Core Data,我有一个代码示例,演示如何更新核心数据中的对象,但我有一个小问题: // Retrieve the context if (managedObjectContext == nil) { managedObjectContext = [(YourAppNameAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; } // Retrieve the entity from the

我有一个代码示例,演示如何更新核心数据中的对象,但我有一个小问题:

// Retrieve the context
if (managedObjectContext == nil) {
    managedObjectContext = [(YourAppNameAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}

// Retrieve the entity from the local store -- much like a table in a database
NSEntityDescription *entity = [NSEntityDescription entityForName:@"YourEntityName" 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:@"YourIdentifyingObjectProperty == %@", yourIdentifyingQualifier];
[request setPredicate:predicate];

// Set the sorting -- mandatory, even if you're fetching a single record/object
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"yourIdentifyingQualifier" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release]; sortDescriptors = nil;
[sortDescriptor release]; sortDescriptor = nil;

// Request the data -- NOTE, this assumes only one match, that 
// yourIdentifyingQualifier is unique. It just grabs the first object in the array. 
YourEntityName *thisYourEntityName = [[managedObjectContext executeFetchRequest:request error:&error] objectAtIndex:0];
[request release];
request = nil;
这一行:

YourEntityName *thisYourEntityName = [[managedObjectContext executeFetchRequest:request error:&error] objectAtIndex:0];
我不明白我应该用什么来代替“YourEntityName”,从我收集的表格中可以看出,帮助我的人是,我必须从数据模型中使用实体名称,但它似乎不起作用,我只得到一个未声明的错误

我有一个名为“Event”的实体,该实体有两个名为userNote和timeStamp的属性


我正在处理一个全新的使用核心数据的清晰分割视图ipad项目。我想在TextViewdEndediting中运行此操作,因此当用户键入完笔记后,它会更新对象。

YourEntityName
替换为用于表示实体的类的名称。如果您在Xcode中为您的实体声明了自定义类,请在此处指定该类。在您的例子中,听起来好像您还没有为您的实体声明自定义类。在这种情况下,使用
NSManagedObject
作为实体类

在Xcode的数据模型编辑器中,可以为实体指定名称和类。它们不是一回事。实体名称用于指代以下语句中的实体:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext];

实体类指定用于该实体的托管对象的类。在使用核心数据时,开发人员通常创建自定义类以用于其实体,但并不需要这样做。如果要为实体使用自定义类,则必须自己创建该类(作为
NSManagedObject
的子类),并在Xcode中的数据模型编辑器中指定该类名。如果不指定自定义类,
NSManagedObject
用于表示实体对象。

ah cool工作,仅在我运行此命令更新对象时:thisYourEntityName.userNote=@“新值”;显然,它不是结构或联合的一部分。在使用核心数据时,不仅可以使用点符号访问属性,而且出于性能原因,苹果建议使用点符号。您可以在与核心数据相关的最新WWDC 2010会话中检查这一点。@不可原谅的优异点。我已经删除了我的错误评论,并将替换为(希望)更好的评论。谢谢你指出我的错误!核心数据为您生成访问器,但您需要做一些工作来抑制编译器警告。有关详细信息,请参阅Apple核心数据编程指南的动态生成的访问器方法部分()。基本上,您可以在
NSManagedObject
上使用自定义类或类别。