If you look into project.pbxproj, you shall see that every file in the project has a hash
For example
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
1D60589F0D05DD5A006BFB54 is the hash for the linked foundation framework.
I wonder how these are calculated i.e. what function is used and what meta information besides the file name goes into the input for the hash.
Objective-C:
uuid_t uuid;
uuid_generate(uuid);
NSString *UUID = @"";
for (int i = 0; i < 12; i++) UUID = [UUID stringByAppendingFormat:@"%02X", uuid[i]];
Python:
def GenerateId(cls):
return ''.join(str(uuid.uuid4()).upper().split('-')[1:])
Sergey's solution is (actually very) good, but I think it might deserve some explanation: the only reason why XCode is using that inhuman format for project.pbxproj
is likely to ensure that each key is unique.
As a matter of fact, I did some tests before reading Sergey's solution and, as long as the hash is unique and the file is consistent (no dangling files or the like...), you can put as hash pretty much what you want (if UUID-like, at least, I didn't try with shorter strings or non HEX digits...).
The accepted answer also confirm this, since UUID4 is a purely random identifier, as stated here:
UUID4 explanation on Wikipedia
which implies that XCode cannot possibly cross-check the resource with the key (as it could do if the keys where MD5 hashes, for instance).
Hope this will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With