-1

in my iPhone application I need to have unique integer value. I need something like GUID bu it should be integer.

revolutionkpi
  • 2,632
  • 10
  • 45
  • 84
  • Within what bounds and scope? A simple counter is unique depending on your scope and usage... – Wain Jul 15 '13 at 08:38

2 Answers2

1

That unique should be unique per device or per user or per application?

If need any of those than you need to take in consideration the available info while generating data. For device you can take the Wi-FI mac address for example and transform it into unique id.

1

There's a reason why GUID's are 128 bits and not 32. The risk for collision is far greater with only 32-bits. You could always generate the 128 bit GUID and only use the last 32 bits. As long as you have some mechanism for handling collision you should be fine.

If you really need to have something that is unique and only 32-bit, the safest way is to have a server incrementally return the next integer.

Just to let you know, the iPhone can handle 128-bit GUIDs, so there is no technical reason (that I can see) not to use normal GUIDs. I would try it, run some tests and if performance is inadequate I would considers changing to 32-bit integers.

Erik B
  • 40,889
  • 25
  • 119
  • 135