Home > Mobile >  What is universally unique identifier (UUID)? In swift
What is universally unique identifier (UUID)? In swift

Time:07-15

What is UUID (universally unique identifier) in swift . I looked at apple documents but I still don't understand what we use for how we use it and what is the use

Thanks.

CodePudding user response:

A UUID is a universally unique identifier, which means if you generate a UUID right now using UUID it's guaranteed to be unique across all devices in the world. This means it's a great way to generate a unique identifier for users, for files, or anything else you need to reference individually – guaranteed.

Here's how to create a UUID as a string:

let uuid = UUID().uuidString

for uniqueness and avoid duplication for saving a person for example Facebook have more than 1 Alex and if they want to identify a specific Alex that is register in fb app then they should must define an identifiable property for Alex like id,

struct Person:Identifiable // identifiable must have id property {
  let id = UUID() //identifier to make an object unique
  let name:String
  let address:String
  let age:Int
}

lets take an another example if your application have million users and you just give away an iPhone with to random person named xyz so there is more than 100 xyz so how you differentiate them?

Yes with universal identifier! you just filter him by id that is unique

  • Related