kelan.io

Easier getenv() in Swift

I wanted to use getenv(3) in Swift, but the generated interface for that function is full of Unsafeness:

func getenv(_: UnsafePointer<Int8>) -> UnsafeMutablePointer<Int8>

Eww.

So, instead you can just use NSProcessInfo:

if let dir = NSProcessInfo().environment["PLAYGROUND_SHARED_DATA_FOLDER"] {
    print(dir)
}