Skip to content

Commit 2d02722

Browse files
committed
update for beta 3
1 parent 1a5070e commit 2d02722

File tree

8 files changed

+72
-15
lines changed

8 files changed

+72
-15
lines changed

bk1ch01p015yourFirstInstance/bk1ch01p015yourFirstInstance/ViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class ViewController: UIViewController {
5151

5252
let sum = 1 + 2
5353
let x = 1.successor()
54-
let y = "hello".generate()
5554

56-
let _ = (sum,x,y) // shut the compiler up
55+
_ = sum
56+
_ = x
5757

5858
1.sayHello() // outputs: "Hello, I'm 1"
5959

bk1ch02p028basicFunctions/bk1ch02p28basicFunctions/ViewController.swift

+15-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ func say1(s:String) -> Void { print(s) }
1313
func say2(s:String) -> () { print(s) }
1414
func say3(s:String) { print(s) }
1515

16+
// crazy but true
1617

17-
func greet1(Void) -> String { return "howdy" }
18+
func greet1(unused:Void) -> String { return "howdy" }
1819
func greet2() -> String { return "howdy" }
1920

20-
func greeet1(Void) -> Void { print("howdy") }
21+
func greeet1(unused:Void) -> Void { print("howdy") }
2122
func greeet2() -> () { print("howdy") }
2223
func greeet3() { print("howdy") }
2324

@@ -45,10 +46,21 @@ class ViewController: UIViewController {
4546

4647
print(z2)
4748

49+
say1("howdy")
50+
say2("howdy")
51+
say3("howdy")
52+
greet1()
53+
greet2()
54+
greeet1()
55+
greeet2()
56+
greeet3()
57+
4858
let pointless : Void = say1("howdy") // showing that we actually return void
4959
print("pointless is \(pointless)") // showing that we captured the returned void
5060

51-
61+
let v : Void = () // passing a void is the same as no parameters
62+
greet1(v)
63+
greet2(v)
5264

5365

5466
}

bk1ch03p095tuple/bk1ch03p095tuple/ViewController.swift

+44-4
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,15 @@ class ViewController: UIViewController {
116116
f2(tuple)
117117
}
118118

119+
do {
120+
// var tuple = (i1:1, i2:2)
121+
// f2(tuple) // compile error
122+
}
123+
119124
do { // examples from the dev forums
120125

126+
/*
127+
121128
var array: [(Int, Int)] = []
122129

123130
// OK - literals
@@ -132,12 +139,45 @@ class ViewController: UIViewController {
132139
array.append(const_tuple)
133140

134141
// NOK - var integer
135-
// var int_var = 1
136-
// array.append(int_var, 1)
142+
var int_var = 1
143+
array.append(int_var, 1)
137144

138145
// NOK - var tuple
139-
// var var_tuple: (Int, Int) = (1, 1)
140-
// array.append(var_tuple)
146+
var var_tuple: (Int, Int) = (1, 1)
147+
array.append(var_tuple)
148+
149+
*/
150+
151+
// However, this changed in Swift 2.0 beta 3:
152+
// New! You can now write it like a tuple!
153+
// parentheses in parentheses
154+
155+
156+
var array: [(Int, Int)] = []
157+
158+
159+
// OK - literals
160+
array.append((1,1))
161+
162+
// OK - let integer
163+
let int_const = 1
164+
array.append((int_const, 1))
165+
166+
// OK - let tuple
167+
let const_tuple: (Int, Int) = (1, 1)
168+
array.append(const_tuple)
169+
170+
// OK - var integer
171+
var int_var = 1
172+
array.append((int_var, 1))
173+
174+
// OK - var tuple
175+
var var_tuple: (Int, Int) = (1, 1)
176+
array.append(var_tuple)
177+
178+
// shut the compiler up
179+
int_var = 0
180+
var_tuple = (0,0)
141181

142182
}
143183

bk1ch04p181optionalProtocolMembers/bk1ch04p181optionalProtocolMembers/ViewController.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ class ViewController: UIViewController {
4949
super.init(nibName: "ViewController", bundle: nil)
5050
}
5151

52-
required init(coder aDecoder: NSCoder) {
52+
required init?(coder aDecoder: NSCoder) {
5353
// fatalError("init(coder:) has not been implemented")
5454
super.init(coder:aDecoder)
5555
}
5656

57+
5758
// inappropriate here, but a legal alternative:
5859

5960
// required convenience init(coder aDecoder: NSCoder) {

bk1ch04p196extensions/bk1ch04p196extensions/ViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ extension Dog where T : Equatable {
5858

5959
}
6060

61-
extension Array where T:Comparable {
62-
func min() -> T {
61+
extension Array where Element:Comparable {
62+
func min() -> Element {
6363
var minimum = self[0]
6464
for ix in 1..<self.count {
6565
if self[ix] < minimum {

bk1ch04p222sets/bk1ch04p222sets/ViewController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ViewController: UIViewController {
3232

3333
do {
3434
let opts = UIViewAnimationOptions(rawValue:0b00011000)
35+
_ = opts
3536
}
3637

3738
do {

bk1ch05p227branching/bk1ch05p227branching/ViewController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class ViewController: UIViewController {
111111

112112
class C1 : NSObject {
113113
override func observeValueForKeyPath(keyPath: String?,
114-
ofObject object: AnyObject?, change: [NSObject : AnyObject]?,
114+
ofObject object: AnyObject?, change: [String : AnyObject]?,
115115
context: UnsafeMutablePointer<()>) {
116116
if keyPath == "readyForDisplay" {
117117
if let obj = object as? AVPlayerViewController {
@@ -128,7 +128,7 @@ class C1 : NSObject {
128128

129129
class C2 : NSObject {
130130
override func observeValueForKeyPath(keyPath: String?,
131-
ofObject object: AnyObject?, change: [NSObject : AnyObject]?,
131+
ofObject object: AnyObject?, change: [String : AnyObject]?,
132132
context: UnsafeMutablePointer<()>) {
133133
if keyPath == "readyForDisplay",
134134
let obj = object as? AVPlayerViewController,
@@ -141,7 +141,7 @@ class C2 : NSObject {
141141

142142
class C3 : NSObject {
143143
override func observeValueForKeyPath(keyPath: String?,
144-
ofObject object: AnyObject?, change: [NSObject : AnyObject]?,
144+
ofObject object: AnyObject?, change: [String : AnyObject]?,
145145
context: UnsafeMutablePointer<()>) {
146146
guard keyPath == "readyForDisplay" else {return}
147147
guard let obj = object as? AVPlayerViewController else {return}

bk1ch05p254memoryManagement/bk1ch05p254memoryManagement/ViewController.swift

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class ViewController: UIViewController {
7474
}
7575
let d = Dog()
7676
let c = Cat()
77+
78+
_ = d
79+
_ = c
7780
}
7881
testRetainCycle() // farewell from Cat, farewell from Dog
7982
}

0 commit comments

Comments
 (0)