Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reference environment variables in Swift? [duplicate]

Tags:

ios

swift

I'm pretty new to Swift and Xcode so please forgive my ignorance. I am trying to set up an environment variable to store my API keys since I am planning on pushing my project to GitHub and don't want the API in a public repo. I read that using environment variables is a good way to do this. I went into Xcode and set up a scheme that included an environment variable like this:

environment variable

how do I actually reference it in Swift? I tried just putting "GMAPS_API" in the code where my API key should go, but it's not recognizing it. Am I even doing this correctly? I have tried to look online, but I am still confused. Any help or pointers in the right direction would be great. Thanks

like image 275
David Avatar asked Dec 09 '16 01:12

David


1 Answers

@OOper pointed me in the right direciton. All I had to do was:

let apiKey = ProcessInfo.processInfo.environment["GMAPS_API"]
like image 125
David Avatar answered Oct 18 '22 18:10

David