-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplates.swift
64 lines (51 loc) · 1.78 KB
/
Templates.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Snippets.swift
//
//
// Created by Jake Young on 1/19/15.
// Website: http://www.thoughtsfromarobot.com
//
// These snippets have been collected or developed
// over my timeline of learning Swift, I did my best
// to credit the original creators, I hope you find them
// useful and helpful. For more resources, please visit
// my website at http://www.thoughtsfromarobot.com
//
// My hope is that you learn from these examples and put them to use
//
//
import Foundation
import UIKit
// MARK: -- Boilerplate Code
// Quickly replace a string within a string
class ParentClass {
let name: String
let numberOfThings: Double
let percentageOfThings: Double
var aComputedProperty: Double {
get {
return numberOfThings * percentageOfThings
}
set {
numberOfThings = newValue / percentageOfThings
}
}
init(name: String, numberOfThings: Double, percentageOfThings: Double) {
self.name = name
self.numberOfThings = numberOfThings
self.percentageOfThings = percentageOfThings
}
}
class ChildClass: ParentClass {
// This class is a child class of ParentClass
// It adds an additional property
let anotherProperty: String
init(name: String, numberOfThings: Double, precentageOfThings: Double, anotherProperty: String) {
self.anotherProperty = anotherProperty
super.init(name: name, numberOfThings: numberOfThings, percentageOfThings: percentageOfThings, anotherProperty)
}
// This convenience initializer takes a name, but sets defaults for the rest of the properties
convenience init(name: String) {
self.init(name: name, numberOfThings: 10.0, precentageOfThings: 0.5, anotherProperty: "Another Property")
}
}