Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift: Testing to see if XcodeColors is installed and enabled #40

Closed
virtualrapha opened this issue Jun 7, 2015 · 6 comments
Closed

Comments

@virtualrapha
Copy link

In the README, you provided a code snippet in C for testing, if XcodeColors is installed and enabled. How would that code look like in Swift?

@ghost
Copy link

ghost commented Oct 11, 2015

I would have expected this to work:

let str = String.fromCString(getenv("XcodeColors")) // String?

It reports nil although the plugin is working
doing setenv("XcodeColors", "NO", 0) does not disable it.

@silan-liu
Copy link

let xcode_colors = getenv("XcodeColors")
 if strcmp(xcode_colors, "YES") == 0 {
     return true
}
return false

try this

@jacobjohnston
Copy link

I'm not getting clear behavior on this either. In Swift, I would expect the code to check whether XcodeColors was installed to be something like this:

let canColor = NSProcessInfo().environment["XcodeColors"] == "YES"

But, that environment variable is always nil. However, if I go set it manually, it can read it fine.

setenv("XcodeColors", "YES", 0)
let canColor = NSProcessInfo().environment["XcodeColors"] == "YES"

The colors DO work, I'm just not able to see if the plugin is installed. Any tips?

@jacobjohnston
Copy link

Nevermind, I understand now. I'm working on an iOS app. The environment variables won't work in iOS because those environment variables are defined on my Mac, not on my iDevice or my simulator. That's a bit of a bummer - I want a way for this to "just work" for the developers that have XcodeColors installed, and gracefully fall back to normal logging for developers that don't. Is there any way to have user-specific environment variables defined for the simulator?

@LightMan
Copy link

Combined with cocoalumberjack, old C style \o/

        DDLog.addLogger(DDTTYLogger.sharedInstance()) // TTY = Xcode console
        let xcode_colors = getenv("XcodeColors");
        if xcode_colors != nil && strcmp(xcode_colors, "YES") == 0 {
            DDTTYLogger.sharedInstance().colorsEnabled = true;
        }

@nesevis
Copy link

nesevis commented Apr 14, 2016

Using this with Alcatraz getenv("XcodeColors") never works. I've implemented the check both with Swift and with Objective C— it is never enabled.

Tips?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants