Creating the Item Class

Your table view needs some rows to display. Each row in the table view will display an item with information such as a name, serial number, and value in dollars.

Create a new Swift file named Item. In Item.swift, define the Item class and give it four properties.

import Foundation
import UIKit

class Item: NSObject {
    var name: String
    var valueInDollars: Int
    var serialNumber: String?
    let dateCreated: Date
}

Item inherits from NSObject. NSObject is the base class that most Objective-C classes inherit from. All of the UIKit classes that you have worked with – UIView, UITextField, and UIViewController, to name a few – inherit either directly or indirectly from NSObject. Your own classes will often need to inherit ...

Get iOS Programming: The Big Nerd Ranch Guide, 6th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.