Generate a UUID on iOS from Swift

前端 未结 6 1749
一向
一向 2020-12-12 09:20

In my iOS Swift app I want to generate random UUID (GUID) strings for use as a table key, and this snippet appears to work:

let uuid = CFUU         


        
6条回答
  •  情歌与酒
    2020-12-12 10:23

    Each time the same will be generated:

    if let uuid = UIDevice.current.identifierForVendor?.uuidString {
        print(uuid)
    }
    

    Each time a new one will be generated:

    let uuid = UUID().uuidString
    print(uuid)
    

提交回复
热议问题