-
Notifications
You must be signed in to change notification settings - Fork 1
/
Item.swift
48 lines (38 loc) · 1.4 KB
/
Item.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Item.swift
// Homepwner
//
// Created by Addison Francisco on 9/25/16.
// Copyright © 2016 Addison Francisco. All rights reserved.
//
import UIKit
class Item: NSObject {
var name: String
var valueInDollars: Int
var serialNumber: String?
let dateCreated: NSDate
init(name: String, serialNumber: String?, valueInDollars: Int) {
self.name = name
self.valueInDollars = valueInDollars
self.serialNumber = serialNumber
self.dateCreated = NSDate()
super.init()
}
convenience init(random: Bool = false) {
if random {
let adjectives = ["Fluffy", "Rust", "Shiny"]
let nouns = ["Bear", "Spork", "Mac"]
var idx = arc4random_uniform(UInt32(adjectives.count))
let randomAdjective = adjectives[Int(idx)]
idx = arc4random_uniform(UInt32(nouns.count))
let randomNoun = nouns[Int(idx)]
let randomName = "\(randomAdjective) \(randomNoun)"
let randomValue = Int(arc4random_uniform(100))
let randomSerialNumber = NSUUID().uuidString.components(separatedBy: "-").first!
self.init(name: randomName, serialNumber: randomSerialNumber, valueInDollars: randomValue)
}
else {
self.init(name: "", serialNumber: nil, valueInDollars: 0)
}
}
}