Skip to content

Instantly share code, notes, and snippets.

@mattmassicotte
Created April 27, 2024 11:11
Show Gist options
  • Save mattmassicotte/b0b772dc66c87ffd02e0f879b66a8cfe to your computer and use it in GitHub Desktop.
Save mattmassicotte/b0b772dc66c87ffd02e0f879b66a8cfe to your computer and use it in GitHub Desktop.

Set value

GCC_PREPROCESSOR_DEFINITIONS = FOO=My Value

Add Constants.m

It is particularly important to check that the definition of your value exists here, as it will not cause a compilation failure, but instead result in the generation of @"FOO".

@import Foundation;

#include <os/base.h>

#ifdef FOO
NSString* const MyConstant = @OS_STRINGIFY(FOO);
#else
#error Undefined
#endif

Bridging Header

@import Foundation;

extern NSString* const MyConstant;

Access it from Swift

print("value: ", MyConstant)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment