Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 漂亮的核心数据对象id_Ios_Swift_Core Data - Fatal编程技术网

Ios 漂亮的核心数据对象id

Ios 漂亮的核心数据对象id,ios,swift,core-data,Ios,Swift,Core Data,从应用程序中删除我的对象,每5分钟与服务器同步一次。用户可以在web中查看他的项目。我为他生成以下链接: "http://mydomain/items/\(self.appDelegate.UUID.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!)/\(items.objectID.URIRepresentation().absoluteString

从应用程序中删除我的对象,每5分钟与服务器同步一次。用户可以在web中查看他的项目。我为他生成以下链接:

"http://mydomain/items/\(self.appDelegate.UUID.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!)/\(items.objectID.URIRepresentation().absoluteString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!)"
UUID
-这是设备或icloud密钥

因此,链接看起来像:

但是我可以剪切
x吗-coredata://60DD8665-3136-4CF0-9FD3-FF9164FC7327
到此:
/Items/p1
。它会是独一无二的吗


或者其他如何使物品id看起来更好的想法。

是的,也许最好创建自己的id,但我找到了另一个解决方案:

let id = Item.objectID.URIRepresentation().absoluteString.componentsSeparatedByString("/p")[1]

结果将是整数值。

显然,您可以依靠对象的id(如果它们是唯一的),而不公开内部核心数据id为什么不创建自己的id并为创建的每个实例分配一个新id呢,如果NSManagedObject的objectID尚未通过保存创建它的上下文来持久化,则它可能会发生更改。依赖您自己的标识符属性,而不是核心数据。