OGeek|极客世界-中国程序员成长平台

标题: iOS:我可以将托管对象存储在字典中吗? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:58
标题: iOS:我可以将托管对象存储在字典中吗?

对于我的 UINotifications,我想在 userInfo 中存储一个唯一键。因此,在我的应用中,您只能为每个 friend 设置一个提醒。所以我想将我的 friend 对象存储为 key 。那可能吗?还是只保存了一个引用,以后无法进行匹配?因为 friend 的名字可能会改变所以我不知道还有什么可以保存在那里以清楚匹配......

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:self.reminderFriend forKey"ReminderForFriend"];
            localNotification.userInfo = infoDict;



Best Answer-推荐答案


您可以使用 friend 的 NSManagedObjectID 实例作为键,因为它是唯一的,您还可以从商店中获取具有该 objectID 的 NSManagedObject 并在以后进行您喜欢的任何类型的比较。 ObjectID 就像主键一样,所以它是唯一的。

-(NSManagedObject *)existingObjectWithIDNSManagedObjectID *)objectID
                                   errorNSError **)error
Fetches the object from the store that has that ID, or nil if it doesn't exist. 

关于iOS:我可以将托管对象存储在字典中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26206389/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4