Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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)?