Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 2.2: GCC_PREPROCESSOR_DEFINITIONS constants no longer imported

Tags:

xcode

swift

The technique to separate API keys in a xcconfig file described in this answer doesn't work with Swift 2.2 due to a bug (SR-909).

Is there any workaround?

like image 218
olivier Avatar asked Mar 28 '16 16:03

olivier


1 Answers

Thanks for pointing to the bug, would not have figured this one out in a while. If it's any help I ended up adding an additional objc constants bridge 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 bridged key in Swift

// xx.swift
...
// let auth = DropboxAuth(appKey: DROPBOX_API_KEY) 
let auth = DropboxAuth(appKey: kDropBoxAPIKey)
...
like image 127
axniks Avatar answered Oct 05 '22 23:10

axniks