Swift 2.2: GCC_PREPROCESSOR_DEFINITIONS constants are no longer imported

The method for splitting API keys in the xcconfig file described in this answer does not work with Swift 2.2 due to an error (SR-909) .

Is there a workaround?

+5
source share
2 answers

Thanks for pointing out the error, I would not have invented it in time. If this helps, I will add an additional bridge of objc constants to Swift and using the bridge constants from swift:

// Constants.h extern NSString *const kDropBoxAPIKey; // Constants.m NSString *const kDropBoxAPIKey = DROPBOX_API_KEY; // xxx-Bridging-Header.h #import "Constants.h" 

Then use the bridge in Swift

 // xx.swift ... // let auth = DropboxAuth(appKey: DROPBOX_API_KEY) let auth = DropboxAuth(appKey: kDropBoxAPIKey) ... 
+5
source

You can declare another similar macro in the header file bridge. Imagine that we have the macro MY_MACRO in the preprocessing definitions. Swift code does not see it. In the bridge header file, we can define another macro:

 #define MY_MACRO2 MY_MACRO 

Now use MY_MACRO2 everywhere in your Swift code. When Apple fixes this problem, you need to rename MY_MACRO2 to MY_MACRO .

0
source

Source: https://habr.com/ru/post/1245926/


All Articles