Can I convert a CFUUID to 30 characters or less?

只谈情不闲聊 提交于 2020-01-14 14:16:05

问题


I need to create an identifier for my iOS user that is unique. Unfortunately the database that it will be saved to has a set length of 30 characters and CFUUID's are 36 (32 if removing the dashes).

Is there a way to make it into a smaller string? I think CFUUID's are hex, so would it be possible to convert it to full ASCII?


回答1:


Jeff Atwood covers this in Equipping our ASCII Armor. A Base64 encoded GUID results in 22 (24 including ==) bytes. There are also other ascii formats you can use based on the post but Base64 will likely be the friendliest with the database server.




回答2:


First, convert your hex string to NSData using something like https://stackoverflow.com/a/7318062/382374 (be sure to strip out the "-"s). Then use something like http://www.imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php to convert the NSData to base64.



来源:https://stackoverflow.com/questions/11150516/can-i-convert-a-cfuuid-to-30-characters-or-less

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!