Since Swift can't access compile variables, I created an objective c extern variable that points to the compile variable.
CompileVaribleConvertor.h
extern NSString * const NetworkApiBasicAuthUsername; CompileVaribleConvertor.m
// AUTH_USERNAME might not be defined depending on the environment we are pointing to #if defined(AUTH_USERNAME) NSString * const NetworkApiBasicAuthUsername = @AUTH_USERNAME; #else NSString * const NetworkApiBasicAuthUsername = nil; #endif NetworkManager.swift
if CSNetworkApiAuthUsername != nil { // Basic auth is required set them } This code used to work on Swift 1.0, but Swift 1.2 gives compile error. Binary operator '!=' cannot be applied to operands of type 'String' and 'nil'
How do I make the extern variable an optional, I tried defining the extern variable as __nullable with no luck
#if/#else/#endifconstruct that tests whether something is defined.