Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Network Programming with Swift 2 Fetching Data From the Web Constructing a URL

Guarding our API Keys

If we post our projects on gitHub and our code contains the API key, does this not give room to someone else stealing it?

1 Answer

joseph leporati
seal-mask
.a{fill-rule:evenodd;}techdegree
joseph leporati
iOS Development Techdegree Student 3,304 Points

This is a common obstacle we have to overcome with Git - and luckily there is a built way we can do this with Github.

You should store these API values in a config file - fetch these when you need to use them throughout your app from this config file. You can then add a .gitignore file to the root directory of your project. Inside .gitignore add the following code:

config.swift //Specific file name
config.txt //Specific file name
api.config //Specific file name

*.cfg  // Wildcard for all files ending with .cfg
*.config // Wildcard for all files ending with .config

To learn more about .gitignore check out this link: CLICK HERE.

Hope that helps!