O'Reilly logo

Swift 2 By Example by Giordano Scalzo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building the Todos screen

Let's move on to populating the View Controller we just created with the proper entities.

Adding entities

The first thing we need to do is create entities, which is really straightforward. Basically, we just need to map the requested fields in struct:

import Foundation

struct Todo: Equatable {
    let description: String
    let list: List
    let dueDate: NSDate
    let done: Bool
    let doneDate: NSDate?
}

func ==(todo1: Todo, todo2: Todo) -> Bool {
    return todo1.description == todo2.description
    && todo1.dueDate == todo2.dueDate
}

struct List {
    let description: String
}

Foundation is the core module in Swift, and it contains fundamental objects, for example, NSDate, which is required to implement every kind of app.

Implementing datastore

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required