Joe Habadas
Joe Habadas

Reputation: 628

Objective-C, NSArray from executableArchitectures

I'm trying to determine the architecture of another file from my application. I'm using my application bundle and comparing it to a different bundle in my example. The methods are in place and they do return values to NSLog, although they are not the values I was expecting. Can anyone make some sense as to how to interpret the returned values?

- (void)whatArch {

        NSArray *x86_64_Arch = [[NSBundle mainBundle] executableArchitectures];
        NSArray *i386_Arch = [[NSBundle bundleWithPath:@"/path/to/other/bundle"] executableArchitectures];
        NSLog(@"%@ %@",[x86_64_Arch componentsJoinedByString:@" "], [i386_Arch componentsJoinedByString:@" "]);

}

The output I get is:

2012-07-09 00:00:59.990 whatArch[2200:403] 16777223 7 18

The [16777223] is the value that returns for the x86_64 bundle, and [7 18] for the (other) i386 bundle. When I read the documentation on executableArchitecture it shows something much different:

Mach-O Architecture

These constants describe the CPU types that a bundle’s executable code may support.

enum {
   NSBundleExecutableArchitectureI386      = 0x00000007,
   NSBundleExecutableArchitecturePPC       = 0x00000012,
   NSBundleExecutableArchitectureX86_64    = 0x01000007,
   NSBundleExecutableArchitecturePPC64     = 0x01000012
};

Upvotes: 0

Views: 201

Answers (1)

jscs
jscs

Reputation: 64002

NSLog(@"%u 0x%x", 0x01000007, 16777223);    // Prints 16777223 0x1000007
NSLog(@"0x%x %u", 18, 0x00000012);    // Prints 0x12 18

I'll leave 7 and 0x7 as an exercise for the reader.

And did you know that Christmas (Dec 25) and Halloween (Oct 31) are actually on the same day?

Upvotes: 3

Related Questions