简体   繁体   English

核心数据更新object导致app崩溃

[英]Updating object in core data causes app to crash

I am fairly new at core data and am having a problem.我在核心数据方面还很陌生,但遇到了问题。 My app currently is quite simple.我的应用程序目前非常简单。 I have a list of users with a username and an email. The app launched and pulls all the users from the local database via core data NSFetchedRequest.我有一个用户名和 email 的用户列表。该应用程序启动并通过核心数据 NSFetchedRequest 从本地数据库中提取所有用户。 The app currently can create, read, and delete with no errors.该应用程序目前可以毫无错误地创建、读取和删除。 I followed the apple tutorial on core data.我遵循了有关核心数据的苹果教程。

The problem I am having is saving an editted user.我遇到的问题是保存编辑过的用户。 When clicking on the user, the edit view controller is shown where the person can edit the username and email of that particular user.单击用户时,将显示编辑视图 controller,用户可以在其中编辑该特定用户的用户名和 email。 When I go to update and save the user, the app crashes.当我 go 更新和保存用户时,应用程序崩溃了。 The error is:错误是:

2012-04-09 17:47:09.757 SEA[7032:fb03] CoreData: error: Serious application error. 2012-04-09 17:47:09.757 SEA[7032:fb03] CoreData:错误:严重的应用程序错误。 Exception was caught during Core Data change processing.在核心数据更改处理期间捕获到异常。 This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.这通常是 NSManagedObjectContextObjectsDidChangeNotification 观察者中的错误。 [ valueForUndefinedKey:]: the entity User is not key value coding-compliant for the key "timeStamp". [ valueForUndefinedKey:]:实体用户不符合键“timeStamp”的键值编码。 with userInfo { NSTargetObjectUserInfoKey = " (entity: User; id: 0x880ec10; data: {\n email = \"sampleUser@gmail.com\";\n username = sampleUser1;\n})"; with userInfo { NSTargetObjectUserInfoKey = " (entity: User; id: 0x880ec10; data: {\n email = \"sampleUser@gmail.com\";\n username = sampleUser1;\n})"; NSUnknownUserInfoKey = timeStamp; NSUnknownUserInfoKey = 时间戳; } 2012-04-09 17:47:09.760 SEA[7032:fb03] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: the entity User is not key value coding-compliant for the key "timeStamp".' } 2012-04-09 17:47:09.760 SEA[7032:fb03] *由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[valueForUndefinedKey:]:实体用户不符合密钥的键值编码”时间戳”。

From the looks of the error, its still seeing the attribute timeStamp even though I deleted that attributed.从错误的外观来看,即使我删除了该属性,它仍然可以看到属性 timeStamp。 The user entity is like to following:用户实体如下所示:

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>


@interface User : NSManagedObject

@property (nonatomic, retain) NSString * username;

@property (nonatomic, retain) NSString * email;

@end

If someone could please help me I would truly appreciate it.如果有人可以帮助我,我将不胜感激。

If you have just edited the Apple sample code is there any mention to updating a property called timeStamp .如果您刚刚编辑了 Apple 示例代码,是否会提到更新名为timeStamp的属性。

Do a project wide search for timeStamp and update as appropriate (eg remove any mention as you are not using it in your model)在项目范围内搜索timeStamp并根据需要进行更新(例如,删除任何提及,因为您没有在模型中使用它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM