I have installed the Xcode plugin for XcodeColors from robbie hanson. (see https://github.com/robbiehanson/XcodeColors)
If I test it in a playground
let dict = NSProcessInfo.processInfo().environment
let env = dict["XcodeColors"] as? String
env would be "YES".
But, if I use the same code in my app, env would be nil, because the app is running on their own process.
Because I would print out colored text with specific esc sequences only if the plugin is installed, I want get the information about the Xcode env var.
How can I do that?
Edit your scheme -> Select the "Run" section -> Select "Arguments" tab -> Add the environment variable.
Be careful, environment variables are not set if you run the app without XCode.
I ran into the same problem with XcodeColors. I ended up solving it with a simple script build phase. It checks to see if XcodeColors is installed or not and sets/adds a key to the Info.plist in the build. So create a new "Run Script Build Phase" and put this in there:
xcodeColorsDir="$USER_LIBRARY_DIR/Application Support/Developer/Shared/Xcode/Plugins/XcodeColors.xcplugin/"
xcodeColorsInstalled=0
if [ -d "$xcodeColorsDir" ]; then
# Directory exists, therefore, XcodeColors is installed
xcodeColorsInstalled=1
fi
infoPlistPath="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
existingValue=$(/usr/libexec/PlistBuddy -c "Print :XcodeColorsInstalled" "$infoPlistPath")
if [ -z "$existingValue" ]; then
# Key already exists so overwrite it
/usr/libexec/PlistBuddy -c "Add :XcodeColorsInstalled bool $xcodeColorsInstalled" "$infoPlistPath"
else
# Key doesn't exist yet
/usr/libexec/PlistBuddy -c "Set :XcodeColorsInstalled $xcodeColorsInstalled" "$infoPlistPath"
fi
Then, you can access the Info.plist param during runtime with something like:
func isColorizedLoggingEnabled() -> Bool {
if let colorizedLoggingEnabled = NSBundle.mainBundle().infoDictionary?["XcodeColorsInstalled"] as? Bool {
return colorizedLoggingEnabled
} else {
return false
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With