Skip to content

Commit 848b3b3

Browse files
committed
more changes for Swift 2.2: protocol generic typealias becomes associatedtype; __FUNCTION__ becomes #function; starting to change string selectors to #selector
1 parent 16eccf4 commit 848b3b3

File tree

44 files changed

+315
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+315
-309
lines changed

bk1ch04p187generics/bk1ch04p187generics/ViewController.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct Bird : Flier {
1313
}
1414

1515
protocol Flier2 {
16-
typealias Other
16+
associatedtype Other
1717
func flockTogetherWith(f:Self.Other) // just showing that this is legal
1818
func mateWith(f:Other)
1919
}
@@ -45,15 +45,15 @@ let vd : Void = flockTwoTogether("hey", 1)
4545

4646
/*
4747

48-
protocol Flier3 {
49-
typealias Other : Flier3
48+
protocol Flier3a {
49+
associatedtype Other : Flier3a
5050
func flockTogetherWith(f:Other)
5151
}
52-
struct Bird3 : Flier3 {
53-
func flockTogetherWith(f:Insect3) {}
52+
struct Bird3a : Flier3a {
53+
func flockTogetherWith(f:Insect3a) {}
5454
}
55-
struct Insect3 : Flier3 {
56-
func flockTogetherWith(f:Insect3) {}
55+
struct Insect3a : Flier3a {
56+
func flockTogetherWith(f:Insect3a) {}
5757
}
5858

5959
*/
@@ -65,7 +65,7 @@ struct Insect3 : Flier3 {
6565
protocol Superflier3 {}
6666

6767
protocol Flier3 : Superflier3 {
68-
typealias Other : Superflier3
68+
associatedtype Other : Superflier3
6969
func flockTogetherWith(f:Other)
7070
}
7171
struct Bird3 : Flier3 {
@@ -98,7 +98,7 @@ func myMin<T:Comparable>(things:T...) -> T {
9898
// it can _only_ be used as a type constraint, as in flockTwoTogether2
9999

100100
protocol Flier4 {
101-
typealias Other
101+
associatedtype Other
102102
}
103103
struct Bird4 : Flier4 {
104104
typealias Other = String
@@ -127,7 +127,7 @@ class NoisyDog2<T> : Dog<T> {} // and this is also legal!
127127
// class NoisyDog3 : Dog<T> {} // but this is not; the superclass generic must be resolved somehow
128128

129129
protocol Flier6 {
130-
typealias Other
130+
associatedtype Other
131131
func fly()
132132
}
133133

bk1ch04p193whereClauses/bk1ch04p193whereClauses/ViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ struct Sword : Wieldable {
1111
struct Bow : Wieldable {
1212
}
1313
protocol Superfighter {
14-
typealias Weapon : Wieldable
14+
associatedtype Weapon : Wieldable
1515
}
1616
protocol Fighter : Superfighter {
17-
typealias Enemy : Superfighter
17+
associatedtype Enemy : Superfighter
1818
func steal(weapon:Self.Enemy.Weapon, from:Self.Enemy)
1919
}
2020
struct Soldier : Fighter {
@@ -43,9 +43,9 @@ protocol Flier {
4343
protocol Walker {
4444
}
4545
protocol Generic {
46-
typealias T : Flier, Walker // T must adopt Flier and Walker
47-
// typealias U where U:Flier // no where clauses on typealias
48-
typealias U : Dog, Flier // legal: this is basically an inheritance declaration!
46+
associatedtype T : Flier, Walker // T must adopt Flier and Walker
47+
// associatedtype U where U:Flier // no where clauses on associatedtype
48+
associatedtype U : Dog, Flier // legal: this is basically an inheritance declaration!
4949
}
5050
func flyAndWalk<T where T:Walker, T:Flier> (f:T) {}
5151
func flyAndWalk2<T : protocol<Walker, Flier>> (f:T) {}

bk1ch04p194whereClauses2/bk1ch04p194whereClauses2/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import UIKit
77
// ==== colon and protocol
88

99
protocol Flier {
10-
typealias Other
10+
associatedtype Other
1111
}
1212
struct Bird : Flier {
1313
typealias Other = String

bk1ch04p199umbrellaTypes/bk1ch04p199umbrellaTypes/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NoisyDog : Dog {}
1717
func anyExpecter(a:Any) {}
1818

1919
protocol Flier {
20-
typealias Other
20+
associatedtype Other
2121
}
2222
struct Bird : Flier {
2323
typealias Other = Insect

bk1ch14Appendix/Appendix/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MyClass {
1414
var timer : NSTimer?
1515
func startTimer() {
1616
self.timer = NSTimer.scheduledTimerWithTimeInterval(1,
17-
target: self, selector: "timerFired:",
17+
target: self, selector: #selector(timerFired(_:)),
1818
userInfo: nil, repeats: true)
1919
}
2020
@objc func timerFired(t:NSTimer) { // will crash without @objc

bk2ch01p045constraintsOrderOfEvents/ch14p398constraintsOrderOfEvents/MyView.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ class MyView: UIView {
2828

2929
override func updateConstraints() {
3030
super.updateConstraints()
31-
print("\(self)\n\(__FUNCTION__)\n")
31+
print("\(self)\n\(#function)\n")
3232
}
3333

3434
// gets an extra cycle, I've no idea why
3535
override func layoutSublayersOfLayer(layer: CALayer) {
3636
super.layoutSublayersOfLayer(layer)
37-
print("\(self)\n\(__FUNCTION__)\n")
37+
print("\(self)\n\(#function)\n")
3838
}
3939

4040
override func layoutSubviews() {
4141
super.layoutSubviews()
42-
print("\(self)\n\(__FUNCTION__)\n")
42+
print("\(self)\n\(#function)\n")
4343
}
4444

4545
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
4646
// super.traitCollectionDidChange(previousTraitCollection)
47-
print("\(self)\n\(__FUNCTION__)\n")
47+
print("\(self)\n\(#function)\n")
4848
// let prev : UITraitCollection? = previousTraitCollection
4949
// if prev == nil {
5050
// print("nil")
@@ -62,6 +62,6 @@ class MyLoggingLayer : CALayer {
6262
override func layoutSublayers() {
6363
super.layoutSublayers()
6464
guard let del = self.delegate else {return}
65-
print("layer of \(del)\n\(__FUNCTION__)\n")
65+
print("layer of \(del)\n\(#function)\n")
6666
}
6767
}

bk2ch01p046transformsAndConstraints/ch14p400transformsAndConstraints/LoggingView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ class LoggingView: UIView {
66

77
override func updateConstraints() {
88
super.updateConstraints()
9-
print("\(self) \(__FUNCTION__)\n")
9+
print("\(self) \(#function)\n")
1010
}
1111

1212
override func layoutSublayersOfLayer(layer: CALayer) {
1313
super.layoutSublayersOfLayer(layer)
14-
print("\(self) \(__FUNCTION__)\n")
14+
print("\(self) \(#function)\n")
1515
}
1616

1717
override func layoutSubviews() {
1818
super.layoutSubviews()
19-
print("\(self) \(__FUNCTION__)\n")
19+
print("\(self) \(#function)\n")
2020
}
2121

2222
}

bk2ch03p101drawingIntoLayer/ch16p450drawingIntoLayer/Smilers.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class Smiler:NSObject {
99
//[[UIImage imageNamed: @"smiley"] drawInRect:CGContextGetClipBoundingBox(ctx)];
1010
UIImage(named:"smiley")!.drawAtPoint(CGPoint())
1111
UIGraphicsPopContext()
12-
print("\(__FUNCTION__)")
12+
print("\(#function)")
1313
print(layer.contentsGravity)
1414
}
1515
}
1616

1717
class Smiler2:NSObject {
1818
override func displayLayer(layer: CALayer) {
1919
layer.contents = UIImage(named:"smiley")!.CGImage
20-
print("\(__FUNCTION__)")
20+
print("\(#function)")
2121
print(layer.contentsGravity)
2222
}
2323
}
@@ -28,15 +28,15 @@ class SmilerLayer:CALayer {
2828
//[[UIImage imageNamed: @"smiley"] drawInRect:CGContextGetClipBoundingBox(ctx)];
2929
UIImage(named:"smiley")!.drawAtPoint(CGPoint())
3030
UIGraphicsPopContext()
31-
print("\(__FUNCTION__)")
31+
print("\(#function)")
3232
print(self.contentsGravity)
3333
}
3434
}
3535

3636
class SmilerLayer2:CALayer {
3737
override func display() {
3838
self.contents = UIImage(named:"smiley")!.CGImage
39-
print("\(__FUNCTION__)")
39+
print("\(#function)")
4040
print(self.contentsGravity)
4141
}
4242
}

bk2ch06p253orientationsPermitted4/ch19p590orientationsPermitted/MyView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import UIKit
33
class MyView : UIView {
44

55
override func layoutSubviews() {
6-
print(__FUNCTION__)
6+
print(#function)
77
super.layoutSubviews()
88
}
99

1010
override func updateConstraints() {
11-
print(__FUNCTION__)
11+
print(#function)
1212
super.updateConstraints()
1313
}
1414

bk2ch06p253orientationsPermitted4/ch19p590orientationsPermitted/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ class ViewController : UIViewController {
119119
// layout events check
120120

121121
override func viewWillLayoutSubviews() {
122-
print(__FUNCTION__)
122+
print(#function)
123123
}
124124

125125
override func viewDidLayoutSubviews() {
126-
print(__FUNCTION__)
126+
print(#function)
127127
}
128128

129129
override func updateViewConstraints() {
130-
print(__FUNCTION__)
130+
print(#function)
131131
super.updateViewConstraints()
132132
}
133133
}

bk2ch06p275tabbedInterface/ch19p611tabbedInterface/FirstViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class FirstViewController : UIViewController, UITabBarControllerDelegate {
1515
func tabBarControllerSupportedInterfaceOrientations(tabBarController: UITabBarController) -> UIInterfaceOrientationMask {
1616
print(self, terminator: "")
1717
print(" ", terminator: "")
18-
print(__FUNCTION__)
18+
print(#function)
1919
return .Portrait }
2020

2121
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
2222
print(self, terminator: "")
2323
print(" ", terminator: "")
24-
print(__FUNCTION__)
24+
print(#function)
2525
return .Landscape // called, but pointless
2626
}
2727

bk2ch06p275tabbedInterface/ch19p611tabbedInterface/SecondViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class SecondViewController : UIViewController {
66
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
77
print(self, terminator: "")
88
print(" ", terminator: "")
9-
print(__FUNCTION__)
9+
print(#function)
1010
return .Landscape // called, but pointless
1111
}
1212

bk2ch06p296customAnimation2/ch19p620customAnimation1/ViewControllers.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ class FirstViewController : UIViewController {
1212

1313
override func viewWillAppear(animated: Bool) {
1414
super.viewWillAppear(animated)
15-
print("\(self) " + __FUNCTION__)
15+
print("\(self) " + #function)
1616
}
1717
override func viewDidAppear(animated: Bool) {
1818
super.viewDidAppear(animated)
19-
print("\(self) " + __FUNCTION__)
19+
print("\(self) " + #function)
2020
}
2121
override func viewWillDisappear(animated: Bool) {
2222
super.viewWillDisappear(animated)
23-
print("\(self) " + __FUNCTION__)
23+
print("\(self) " + #function)
2424
}
2525
override func viewDidDisappear(animated: Bool) {
2626
super.viewDidDisappear(animated)
27-
print("\(self) " + __FUNCTION__)
27+
print("\(self) " + #function)
2828
}
2929

3030

@@ -33,23 +33,23 @@ class FirstViewController : UIViewController {
3333
class SecondViewController : UIViewController {
3434
override func viewWillAppear(animated: Bool) {
3535
super.viewWillAppear(animated)
36-
print("\(self) " + __FUNCTION__)
36+
print("\(self) " + #function)
3737
if let tc = self.transitionCoordinator() {
3838
print(tc)
3939
}
4040

4141
}
4242
override func viewDidAppear(animated: Bool) {
4343
super.viewDidAppear(animated)
44-
print("\(self) " + __FUNCTION__)
44+
print("\(self) " + #function)
4545
if let tc = self.transitionCoordinator() {
4646
print(tc)
4747
}
4848

4949
}
5050
override func viewWillDisappear(animated: Bool) {
5151
super.viewWillDisappear(animated)
52-
print("\(self) " + __FUNCTION__)
52+
print("\(self) " + #function)
5353

5454
if let tc = self.transitionCoordinator() {
5555
print(tc)
@@ -58,7 +58,7 @@ class SecondViewController : UIViewController {
5858
}
5959
override func viewDidDisappear(animated: Bool) {
6060
super.viewDidDisappear(animated)
61-
print("\(self) " + __FUNCTION__)
61+
print("\(self) " + #function)
6262
if let tc = self.transitionCoordinator() {
6363
print(tc)
6464
}

bk2ch06p300customAnimation3/ch19p620customAnimation1/ViewControllers.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ class FirstViewController : UIViewController {
1212

1313
override func viewWillAppear(animated: Bool) {
1414
super.viewWillAppear(animated)
15-
print("\(self) " + __FUNCTION__)
15+
print("\(self) " + #function)
1616
}
1717
override func viewDidAppear(animated: Bool) {
1818
super.viewDidAppear(animated)
19-
print("\(self) " + __FUNCTION__)
19+
print("\(self) " + #function)
2020
}
2121
override func viewWillDisappear(animated: Bool) {
2222
super.viewWillDisappear(animated)
23-
print("\(self) " + __FUNCTION__)
23+
print("\(self) " + #function)
2424
}
2525
override func viewDidDisappear(animated: Bool) {
2626
super.viewDidDisappear(animated)
27-
print("\(self) " + __FUNCTION__)
27+
print("\(self) " + #function)
2828
}
2929

3030

@@ -33,19 +33,19 @@ class FirstViewController : UIViewController {
3333
class SecondViewController : UIViewController {
3434
override func viewWillAppear(animated: Bool) {
3535
super.viewWillAppear(animated)
36-
print("\(self) " + __FUNCTION__)
36+
print("\(self) " + #function)
3737
}
3838
override func viewDidAppear(animated: Bool) {
3939
super.viewDidAppear(animated)
40-
print("\(self) " + __FUNCTION__)
40+
print("\(self) " + #function)
4141
}
4242
override func viewWillDisappear(animated: Bool) {
4343
super.viewWillDisappear(animated)
44-
print("\(self) " + __FUNCTION__)
44+
print("\(self) " + #function)
4545
}
4646
override func viewDidDisappear(animated: Bool) {
4747
super.viewDidDisappear(animated)
48-
print("\(self) " + __FUNCTION__)
48+
print("\(self) " + #function)
4949
}
5050

5151
}

0 commit comments

Comments
 (0)