There are two ways to determine this: at runtime (i.e. in your running code), and at compile time (i.e. before the code is compiled). Let’s take a look at both options.
Runtime Check
1 2 3 4 5 6 7 8 |
// testing for 64bit at runtime if (sizeof(void*) == 4) { self.textLabel.text = @"You're running in 32 bit"; } else if (sizeof(void*) == 8) { self.textLabel.text = @"You're running in 64 bit"; } |
Determines the size of a pointer.
Compile Time Check
1 2 3 4 5 |
#if __LP64__ // you're running 64bit #else // you're running 32bit #endif |
Asks the compiler which architecture it compiles for.
I guess this runtime check, checks if your app is compiled in 32 or 64 bit. So it is the same as the compile time check.
It does not check what the underlying OS is (32 or 64bit), am I right?
Hi Giannis, from what I understand the runtime check determines the size of the pointer in a running app, no matter how it was compiled (in 32 or 64 bit). It doesn’t not check the operating system. The compiler on the other hand, or more accurately, Xcode would do that for us.
Keep in mind this was relevant in 2013 when we could still deliver apps depending on what bit-ness the hardware supported. I guess as of 2018/2019 it’s a moot point because Xcode won’t let us compile apps in 32 bit anymore, on any currently supported OS or hardware.