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

Best way to keep data saved on an application with swift?

I have an app that i need to calculate numbers with, my question is, if i create 3 empty arrays to store numbers in, will those number be saved after the app is closed? Also will i be able to continue to add to those arrays? Or is there some other route to take to save this information and use it at the same time while the app is running and still have it available for when the app re-opens?

1 Answer

Shane, any data stored in an array will be lost when the app closes.

Basically there are 3 ways to store data in iOS (at least as far as I know): pLists, SQLite, Core Data

Each has its own pluses and minuses. pLists is probably the way to go if you only have data in a couple of arrays to store. And there's a Treehouse course that shows you how using Swift. Sorry, did it a while ago and can't remember for sure which one it is. But I think it's the course that does the FunFact app. There is also a Treehouse course on CoreData, but it uses Objective-C, which may not be what you are interested in.

Is there a way to create a button1 and a button2 with a while loop in button1. The while loop would only work after button1 has been touched once so the while loop would work on touch 2 and on, and make it so it also only works when button2 hasnt been touched?

so something like this?

IBAction(Button1)(Sender: Any) {

while (Button1 Touch > 1 && Button2 Touch !> 0) { // my code... } } How would I Go About this?