Ryanc
Ryanc

Reputation: 111

How to store information in a to-do list app

I'm following Ray Wenderlich's tutorial right now (http://www.raywenderlich.com/77974/making-a-gesture-driven-to-do-list-app-like-clear-in-swift-part-1). Whenever I run my app it comes up with the same information that is listed in the code:

class ViewController: UIViewController {

@IBOutlet weak var tableView: UITableView!
var toDoItems = [ToDoItem]()

override func viewDidLoad() {
    super.viewDidLoad()

    if toDoItems.count > 0 {
        return
    }
    toDoItems.append(ToDoItem(text: "feed the cat"))
    toDoItems.append(ToDoItem(text: "buy eggs"))
    toDoItems.append(ToDoItem(text: "watch WWDC videos"))
    toDoItems.append(ToDoItem(text: "rule the Web"))
    toDoItems.append(ToDoItem(text: "buy a new iPhone"))
    toDoItems.append(ToDoItem(text: "darn holes in socks"))
    toDoItems.append(ToDoItem(text: "write this tutorial"))
    toDoItems.append(ToDoItem(text: "master Swift"))
    toDoItems.append(ToDoItem(text: "learn to draw"))
    toDoItems.append(ToDoItem(text: "get more exercise"))
    toDoItems.append(ToDoItem(text: "catch up with Mom"))
    toDoItems.append(ToDoItem(text: "get a hair cut"))
}

Even if I delete the line "get a hair cut" when I restart the app, the "get a hair cut" reappears. If I were to submit the app to the Appstore, would the same thing happen when opening the app on my iPhone? How can I make it so that the app saves when I add and delete to-do list items? Thank you!

Upvotes: 0

Views: 132

Answers (1)

Bouke
Bouke

Reputation: 12168

The code listed in the example uses a temporary storage. If you restart the app. All changes will be lost. You can use CoreData for permanent storage.

Upvotes: 1

Related Questions