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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.