开发者

core data simple update?

开发者 https://www.devze.com 2023-01-05 19:16 出处:网络
I\'m a beginner on core data and try to understand how to simply update an ob开发者_Go百科ject which is already stored.

I'm a beginner on core data and try to understand how to simply update an ob开发者_Go百科ject which is already stored.

myObject is a NsManagedObject

setValue forKey needs .. a key but how could I update with something like setValue:mynewvalue forkey:myObject.key

ok that's not the way.


First, if you can, create your own custom NSManagedObject subclasses with mogenerator. It'll save you a lot of time getting data in and out of Core Data.

If you have to go with the generic NSManagedObject route, try this:

id objectKey = @"key";
id valueToStore = @"Save this";

NSManagedObject *myObj = ...;
[myObj setValue:valueToStore forKey:objectKey];

and to update it, try:

[myObj setValue:@"my new value" forKey:objectKey];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号