gpt4 book ai didi

iOS:我可以将托管对象存储在字典中吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:36 24 4
gpt4 key购买 nike

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

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

最佳答案

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

-(NSManagedObject *)existingObjectWithID:(NSManagedObjectID *)objectID
error:(NSError **)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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com