Creating a unique id for a Core Data program on the iPhone

前端 未结 9 1544
暖寄归人
暖寄归人 2020-12-04 07:28

I am having a bit of trouble figuring out this Core Data stuff. How do I create a new entry with a unique ID? In SQL I would just declare one field as an autoincrement fie

9条回答
  •  执笔经年
    2020-12-04 08:01

    Take a look at NSProcessInfo / ProcessInfo from where we can fetch unique id.

    Objective-C code snippet:

    [[NSProcessInfo processInfo] globallyUniqueString].

    Swift code snippet:

    let uniqueId = ProcessInfo().globallyUniqueString
    print("uniqueId: \(uniqueId)")
    

    Apple Docs:

    Global ID for the process. The ID includes the host name, process ID, and a time stamp, which ensures that the ID is unique for the network, which is handy if you don't want people guessing the id.

提交回复
热议问题