在目标C中生成唯一的ID [英] Generating a unique ID in Objective C
问题描述
我们如何在目标C中获得唯一的ID.我想为我的会话创建一个唯一的ID,然后在每次服务器调用发生时生成一个ID.每次此ID都应该是唯一的.
我尝试使用CFUUID类,该类为我们提供了巨大的唯一ID(4FE9D00C-531E-45E8-B10E-11968ACC36E9).我想要一个较小的唯一ID.
有任何线索吗?
guid(通过剪切组合)生成唯一的id.如果您想要的字符较少,那么一种选择是对GUID进行base64编码.这样每个字符有64种可能性,而不是16种(0-9,A-F)
此:
<代码> 540c2d5f-a9ab-4414-bd36-9999f5388773
成为:
Xy0MVKupFES9NpmZ9TiHcw
例如:(不过是C#)如何在iphone-sdk上进行base64编码? >
How do we get unique IDs in Objective C. I want to create a unique ID for my session & then generate a ID each time a server call happens. Each time this ID should be unique.
I tried using CFUUID class which gives us a huge unique ID (4FE9D00C-531E-45E8-B10E-11968ACC36E9). I want a unique ID of smaller size.
Any clue?
A guid (by shear combinations) generates a unique id. If it's less characters you want then one option is to base64encode the guid. That allows for 64 possibilities per char instead of 16 (0-9, A-F)
This:
540c2d5f-a9ab-4414-bd36-9999f5388773
Becomes:
Xy0MVKupFES9NpmZ9TiHcw
For example: (C# though) http://www.singular.co.nz/blog/archive/2007/12/20/shortguid-a-shorter-and-url-friendly-guid-in-c-sharp.aspx
Here's a SO post on objective-c encode/decode (look @ Mike Ho post):
How do I do base64 encoding on iphone-sdk?
这篇关于在目标C中生成唯一的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!