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

Nivit Kochhar
Nivit Kochhar
2,502 Points

Variables Over Multiple View Controllers

I'm trying to develop a personality quiz app and in order to do that I need to maintain a count of the end result of the answers. Each time I create a counter, it is only local to the class/viewcontroller it is created in.

Can someone please tell me how I can maintain counters over multiple view controllers?

3 Answers

You can store them in NSUserDefaults for persistence between view controllers.

Yes NSUserDefaults is stored in the iPhone's internal memory. So it will only be available on the phone is running on.

If you want to made that data available to multiple devices you need a Backend like Parse.com

:)

Yeah, check out Parse! also review the Self-Destructing Message iPhone App course. It goes over Parse and storing data via Parse.

Nivit Kochhar
Nivit Kochhar
2,502 Points

Thanks!

But by storing them in NSUserDefaults won't the variables be local only to my machine and not to others (say when I publish this app)?