Skip to content

Commit d71f401

Browse files
committed
a few tweaks based on proofreading of the first book
1 parent 5c8872b commit d71f401

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

bk1ch05p254memoryManagement/bk1ch05p254memoryManagement/ViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class ViewController: UIViewController {
210210
[weak f] in
211211
print(f)
212212
}
213+
f.function!() // proving that what's printed is Optional
213214
}
214215
testFunctionHolder() // farewell from FunctionHolder
215216
}
@@ -229,6 +230,7 @@ class ViewController: UIViewController {
229230
guard let f = f else { return }
230231
print(f) // strong
231232
}
233+
f.function!() // proving that what's printed is non-Optional
232234
}
233235
testFunctionHolder() // farewell from FunctionHolder
234236
}

bk1ch10p428foundationClasses/bk1ch10p428foundationClasses/ViewController.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ class ViewController: UIViewController {
2020
print("it wasn't found")
2121
}
2222
}
23+
24+
do {
25+
let r = NSRange(1...3)
26+
print(r)
27+
let r2 = r.toRange()
28+
print(r2)
29+
// let r3 = Range(r)
30+
// print(r3)
31+
}
2332

2433
do {
2534
let s = "hello"
@@ -133,6 +142,15 @@ class ViewController: UIViewController {
133142
_ = sum
134143
}
135144

145+
do {
146+
// perhaps the first example is more convincing if we use a variable
147+
let ud = NSUserDefaults.standardUserDefaults()
148+
let i = 0
149+
ud.setInteger(i, forKey: "Score")
150+
ud.setObject(i, forKey: "Score")
151+
152+
}
153+
136154
do {
137155
let ud = NSUserDefaults.standardUserDefaults()
138156
let c = UIColor.blueColor()

bk1ch14Appendix/Appendix/ViewController.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class MyClass {
2323
}
2424
}
2525

26+
struct Pair {
27+
let x : Int
28+
let y : Int
29+
}
30+
2631

2732
class ViewController: UIViewController {
2833

@@ -44,6 +49,12 @@ class ViewController: UIViewController {
4449
override func viewDidLoad() {
4550
super.viewDidLoad()
4651

52+
do {
53+
// proving that Swift structs don't get the zeroing initializer
54+
// let p = Pair()
55+
let pp = CGPoint()
56+
}
57+
4758
do {
4859

4960
// conversion of String to C string

bk2ch06p253orientationsPermitted/ch19p590orientationsPermitted/ViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class ViewController : UIViewController {
1111

1212
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
1313

14-
// NB deprecated in iOS 9 - but why? there still needs to be a way to learn this
1514
print(UIApplication.sharedApplication().statusBarOrientation.rawValue)
1615

1716
print(UIDevice.currentDevice().orientation.rawValue)

bk2ch06p253orientationsPermitted4/ch19p590orientationsPermitted/ViewController.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class ViewController : UIViewController {
3535
print("self \(self.interfaceOrientation.rawValue)")
3636
// but the above is deprecated in iOS 8
3737
print("status bar \(UIApplication.sharedApplication().statusBarOrientation.rawValue)")
38-
// but the above is deprecated in iOS 9 - wrongly, in my opinion
3938
}
4039
// return super.supportedInterfaceOrientations()
4140
return .All // this includes upside down if info.plist includes it
@@ -50,7 +49,6 @@ class ViewController : UIViewController {
5049
print("self \(self.interfaceOrientation.rawValue)")
5150
// but the above is deprecated in iOS 8
5251
print("status bar \(UIApplication.sharedApplication().statusBarOrientation.rawValue)")
53-
// but the above is deprecated in iOS 9 - wrongly, in my opinion
5452
}
5553
// return true
5654
return self.shouldRotate

0 commit comments

Comments
 (0)