9

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.

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
inteist
  • 493
  • 8
  • 15

2 Answers2

12

The reference is not in fact a hash, but rather a unique identifier.

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:])
Terry Burton
  • 2,801
  • 1
  • 29
  • 41
Sergei Nikitin
  • 788
  • 7
  • 12
  • I am not sure I understand your answer. In the Python code the input (cls) does not seem to be used at all to generate the return value. Can you edit your answer to add more explanations, please. – inteist Mar 26 '14 at 20:23
  • Sorry, I'm not a Python programmer, but sometimes I use some scripts. This string is from https://github.com/kronenthaler/mod-pbxproj/blob/master/mod_pbxproj.py - you can inspect whole file and find more info. – Sergei Nikitin Mar 27 '14 at 06:14
  • Not exactly 100% what I was looking for but that's the most information I got. Thanks! – inteist Sep 22 '14 at 23:49
  • Javascript: uuidv4().toUpperCase().split('-').slice(1).join('') – abumalick May 15 '22 at 17:52
6

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

Rick77
  • 3,121
  • 25
  • 43