开发者

Saving the NSManagedObjectID from one entity as a property on a different Entity?

I have a Core Data Entity that needs to hold onto the NSManagedObjectID of some other Entity. To do so I was considering converting the ObjectID to a string that is an approved type of an NSManagedObject attribute.

I can read from the documentation that I can get a URI representation of the ID by:

NSURL *uriID = [[myEntity objectID] URIRepresentation];

I can then convert this URL to an NSString by:

NSString *stringID = [uriID absoluteString];

This I can persist to my NSManagedObject's NSString attribute.

Now what happens when I need to go the other way?

I would like to be able to do something like this:

if([myManagedObject objectID] == value) 

where value is the NSManagedObjectID that I converted to an NSString earlier.

To shed a little more light on the why: I need to 开发者_Go百科be able to have an Entity object hold and persist the ObjectID of another Entity object, so that I later on can go: this Objects last "interaction" was with this Entity.

Hope someone can help me get this working:) Thank you


Why not just establish a to-one relationship property in Object called interaction, which points to an instance of an Entity — and vice verse, a to-many relationship from Entity to Object called interactions? This solves the problem pretty neatly, without all the conversion methods.

But you might also look at the -managedObjectIDForURIRepresentation: and +URLWithString: methods to go the other direction.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜