Objective-C, separating code by architecture

In my Obj-C wrapper object, I am wanting to surround some code with #define checking to be able to target specific targets - arm64 or Simulator.

It would appear that we can "create" custom defines in the project settings : Apple Clang - Preprocessing -> Preprocessor Macros

I have tried defining 'ARM64' under the section 'Debug' for 'Any IOS Sdk', presuming that this will be for a real iPad and thus an arm64 environment - as opposed to the simulator, an x86 environment.

I then put

#ifdef ARM64
...
#else
...
#endif

around my code, but the compiler is still complaining about 64bit calls.

Can this actually be done, as we are able to do from within swift ? Am I going about this the right way ?

Ok, I have got a bit further. The define is indeed present and the preprocessor skips over the 64bit calls I want to avoid for the simulator/preview.

It is now falling over the inclusion of 64bit static libraries which need to be linked with the application, but are not needed when previewing the UI from within Xcode and SwiftUI.

Is it possible to have "conditional" linking ?

By that I mean, if we are building for arm64, link the libraries in, otherwise ignore them.

This is not an issue any more, sorry for the unnecessary question.

When I refresh the preview, all compiles ok and the libraries are ignored.

Shame that I cannot delete this question ...

Rather that defining your own macros, you'll be better off using the macros already provided by the SDK. First, figure out what the exact thing you're trying to accomplish is — are you trying to define the difference between device and simulator, or between Intel and Apple Silicon? Those are separate goals. arm64 simulators exist (on M1 Macs), so a simple architecture definition won't correctly handle simulators.

Once you define your goal, then look at the macros provided in TargetConditionals.h, such as TARGET_CPU_ARM64, TARGET_CPU_X86_64, and TARGET_OS_SIMULATOR.

Objective-C, separating code by architecture
 
 
Q