U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z...
Transcript of U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z...
![Page 1: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/1.jpg)
Cocoa
MDCC 16
- 2016 9 24
![Page 2: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/2.jpg)
• ・初
• ・相知
• ・
• ・陪伴
![Page 3: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/3.jpg)
+
• ・初 - Swi'
• ・相知
• ・
• ・陪伴
![Page 4: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/4.jpg)
Swift 2
• ・初 - Swi'
• ・相知 -
• ・
• ・陪伴
![Page 5: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/5.jpg)
• ・初 - Swi'
• ・相知 -
• ・ -
• ・陪伴
![Page 6: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/6.jpg)
• ・初 - Swi'
• ・相知 -
• ・ -
• Model (Networking)
• View
• ViewController
• ・陪伴
![Page 7: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/7.jpg)
・初 Swi%
Protocol
![Page 8: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/8.jpg)
Swift 50 protocol Swift
protocol Greetable { var name: String { get } func greet()}
![Page 9: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/9.jpg)
Swift
Object-oriented
![Page 10: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/10.jpg)
AnimalTiger
Animal.leg
class Animal { var leg: Int { return 2 } func eat() { print("eat food.") } func run() { print("run with \(leg) legs") }}
class Tiger: Animal { override var leg: Int { return 4 } override func eat() { print("eat meat.") }}
let tiger = Tiger()tiger.eat() // "eat meat"tiger.run() // "run with 4 legs"
![Page 11: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/11.jpg)
ViewController → UIViewController
class ViewCotroller: UIViewController{
//
// view, isFirstResponder()...
//
func myMethod() {
}}
![Page 12: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/12.jpg)
AnotherViewController → UITableViewController → UIViewController
class AnotherViewController: UITableViewController{
//
// tableView, isFirstResponder()...
//
func myMethod() {
}}
![Page 13: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/13.jpg)
Cross-Cu'ng Concerns
![Page 14: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/14.jpg)
... ..
• Copy & Paste
• BaseViewController
•
•
![Page 15: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/15.jpg)
...
![Page 16: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/16.jpg)
...
☑ UITableViewController.tableView☑ ViewController.myMethod
![Page 17: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/17.jpg)
![Page 18: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/18.jpg)
C++
Diamond Problem
![Page 19: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/19.jpg)
Objective-C Small Talk OC
Objec&ve-CMessage Sending
![Page 20: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/20.jpg)
ViewController *v1 = ...[v1 myMethod];
AnotherViewController *v2 = ...[v2 myMethod];
NSArray *array = @[v1, v2];for (id obj in array) { [obj myMethod];}
![Page 21: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/21.jpg)
NSObject *v3 = [NSObject new]
// v3 `myMethod`
NSArray *array = @[v1, v2, v3];for (id obj in array) { [obj myMethod];}
// Runtime error:// unrecognized selector sent to instance blabla
![Page 22: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/22.jpg)
Dynamic Dispatch Safety
![Page 23: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/23.jpg)
OC
OOP
•
•
•
![Page 24: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/24.jpg)
Protocol
![Page 25: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/25.jpg)
Java, C#
Interface
![Page 26: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/26.jpg)
Swift
protocol
![Page 27: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/27.jpg)
Swi$ protocol
protocol Greetable { var name: String { get } func greet()}
![Page 28: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/28.jpg)
OOP
Swi$ protocol
protocol Greetable { var name: String { get } func greet()}
struct Person: Greetable { let name: String func greet() {
print(" \(name)")
}}Person(name: "Wei Wang").greet()
![Page 29: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/29.jpg)
OOP
・初• Objec've-C OOP
•
![Page 30: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/30.jpg)
・相知
![Page 31: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/31.jpg)
OOP
OOP
•
•
•
![Page 32: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/32.jpg)
Person Greetable Greetable
protocol Greetable { var name: String { get } func greet()}
struct Person: Greetable { let name: String func greet() {
print(" \(name)")
}}
![Page 33: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/33.jpg)
protocol Greetable { var name: String { get } func greet()}
struct Cat: Greetable { let name: String func greet() { print("meow~ \(name)") }}
![Page 34: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/34.jpg)
let array: [Greetable] = [ Person(name: "Wei Wang"), Cat(name: "onevcat")]for obj in array { obj.greet()}
// Wei Wang
// meow~ onevcat
![Page 35: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/35.jpg)
Greetbale
struct Bug: Greetable { let name: String}
// Compiler Error: // 'Bug' does not conform to protocol 'Greetable'// protocol requires function 'greet()'
![Page 36: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/36.jpg)
Swift
OOP
• ✅
•
•
![Page 37: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/37.jpg)
protocol P { func myMethod()}
![Page 38: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/38.jpg)
Copy Paste
// class ViewController: UIViewControllerextension ViewController: P { func myMethod() { doWork() }}
// class AnotherViewController: UITableViewControllerextension AnotherViewController: P { func myMethod() { doWork() }}
![Page 39: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/39.jpg)
Swift WWDC Swift 2 Apple
Swift
Swi$ 2 -
![Page 40: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/40.jpg)
protocol P { func myMethod()}
extension P { func myMethod() { doWork() }}
P
![Page 41: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/41.jpg)
extension ViewController: P { }extension AnotherViewController: P { }
viewController.myMethod()anotherViewController.myMethod()
![Page 42: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/42.jpg)
protocol P { func myMethod()}
extension P { func myMethod() { doWork() }
func anotherMethod() { myMethod() someOtherWork() }}
viewController.anotherMethod()
![Page 43: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/43.jpg)
•
•
•
•
•
•
![Page 44: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/44.jpg)
OOP
• ✅
• ✅
•
![Page 45: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/45.jpg)
![Page 46: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/46.jpg)
protocol Nameable { var name: String { get }}
protocol Identifiable { var name: String { get } var id: Int { get }}
![Page 47: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/47.jpg)
struct Person: Nameable, Identifiable { let name: String let id: Int}
// `name` Nameable Identifiable name
![Page 48: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/48.jpg)
...
extension Nameable { var name: String { return "default name" }}
struct Person: Nameable, Identifiable { // let name: String let id: Int}
// Identifiable Nameable extension name
![Page 49: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/49.jpg)
extension Nameable { var name: String { return "default name" }}
extension Identifiable { var name: String { return "another default name" }}
struct Person: Nameable, Identifiable { // let name: String let id: Int}
// name
![Page 50: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/50.jpg)
extension Nameable { var name: String { return "default name" }}
extension Identifiable { var name: String { return "another default name" }}
struct Person: Nameable, Identifiable { let name: String let id: Int}
Person(name: "onevcat", id: 123).name // onevcat
![Page 51: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/51.jpg)
protocol extension
Swift
OOP
• ✅
• ✅
• ❓
![Page 52: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/52.jpg)
・
![Page 53: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/53.jpg)
... POP
WWDC 15 #408Protocol-Oriented Programming in Swi3
![Page 54: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/54.jpg)
Model (Networking)
![Page 55: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/55.jpg)
Protocol
![Page 56: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/56.jpg)
...
Demo
•
•
•
•
•
![Page 57: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/57.jpg)
• Networking:
• AFNetworking
• Alamofire
• (ASIHTTPRequest) !
• Model Parser
• SwiAyJSON
• Argo
• Himotoki
![Page 58: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/58.jpg)
![Page 59: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/59.jpg)
![Page 60: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/60.jpg)
APIKit1 + Himotoki2
2 h$ps://github.com/ikesyo/Himotoki
1 h$ps://github.com/ishkawa/APIKit
![Page 61: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/61.jpg)
UIKit UI
View
![Page 62: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/62.jpg)
xib view
![Page 63: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/63.jpg)
xib view
• View Class
• MyCell
• view xib
• MyCell.xib
• View
• let myCell = MyCell.createFromNib()
![Page 64: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/64.jpg)
protocol NibCreatable { static func createFromNib(owner: Any?) -> Self?}
![Page 65: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/65.jpg)
extension NibCreatable { static func createFromNib(owner: Any?) -> Self? { guard let nibName = nibName else { return nil } let bundleContents = Bundle.main .loadNibNamed(nibName, owner: owner, options: nil) guard let result = bundleContents?.last as? Self else { return nil } return result }
static var nibName: String? { guard let n = NSStringFromClass(Self.self) .components(separatedBy: ".").last else { return nil } return n }}
// Cannot convert value of type 'Self.Type' to // expected argument type 'AnyClass' (aka 'AnyObject.Type')
![Page 66: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/66.jpg)
extension NibCreatable where Self: Any { static func createFromNib(owner: Any?) -> Self? { guard let nibName = nibName else { return nil } let bundleContents = Bundle.main .loadNibNamed(nibName, owner: owner, options: nil) guard let result = bundleContents?.last as? Self else { return nil } return result }
static var nibName: String? { guard let n = NSStringFromClass(Self.self) .components(separatedBy: ".").last else { return nil } return n }}
![Page 67: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/67.jpg)
extension NibCreatable { static func createAndAdd(to superView: UIView) {
}}
![Page 68: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/68.jpg)
extension NibCreatable where Self: UIView { static func createAndAdd(to superView: UIView) { if let view = createFromNib(owner: nil) { superView.addSubview(view) } }}
![Page 69: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/69.jpg)
extension NibCreatable where Self: UIView { static func createAndAdd(to superView: UIView) { if let view = createFromNib(owner: nil) { superView.addSubview(view) // view.backgroundColor = .clear // ... } }}
![Page 70: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/70.jpg)
final class MyCell: UIView { @IBOutlet weak var label: UILabel! //...}
extension MyCell: NibCreatable {
//
}
let cell = MyCell.createFromNib()view.addSubView(cell)
MyCell.createAndAdd(to: view)
![Page 71: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/71.jpg)
UIView extension UIView nib view nib
UIView extension
extension UIView { static func createFromNib(owner: Any?) -> UIView? { //... }
static func createAndAdd(to superView: UIView) { //... }}
![Page 72: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/72.jpg)
where
![Page 73: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/73.jpg)
Controller
![Page 74: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/74.jpg)
Overlay
![Page 75: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/75.jpg)
tableview
![Page 76: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/76.jpg)
UI
class OverlayView: UIView { //...}
let overlay = OverlayView(frame: f)view.addSubview(overlay)
![Page 77: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/77.jpg)
UI
•
• ViewController
!
![Page 78: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/78.jpg)
xib
let overlay = NSBundle.mainBundle() .loadNibNamed("my_overlay_view", owner: nil, options: nil) .last as? UIViewview.addSubview(overlay)
![Page 79: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/79.jpg)
xib
• nib
• ViewController
!
![Page 80: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/80.jpg)
![Page 81: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/81.jpg)
protocol OverlayPresentable { associatedtype Overlay: UIView var overlay: Overlay { get }}
extension OverlayPresentable where Self: UIViewController { func showOverlay() { view.addSubview(overlay) }
func removeOverlay() { overlay.removeFromSuperview() }}
![Page 82: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/82.jpg)
extension ViewController: OverlayPresentable {}class ViewController: UIViewController { let overlay = MyView.createFromNib(owner: nil)!
func someMethod() { //... showOverlay()
//... removeOverlay() }}
![Page 83: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/83.jpg)
•
•
•
!
![Page 84: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/84.jpg)
![Page 85: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/85.jpg)
struct Pagination<T> { let items: [T] let hasNext: Bool}
struct ChannelsResquest: Request { typealias Response = Pagination<Channel> let lastId: Int?}
![Page 86: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/86.jpg)
class ChannelsTableViewController: UITableViewController { private var lastId: Int? = nil private var hasNext = true
override func viewDidLoad() { super.viewDidLoad() load() }
func load() { if hasNext { client.send(ChannelsResquest(lastId: lastId)) { result in } } }}
![Page 87: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/87.jpg)
class ChannelsTableViewController: UITableViewController { private var lastId: Int? = nil private var hasNext = true
private var data: [Channel] = []
override func viewDidLoad() { super.viewDidLoad() load() }
func load() { if hasNext { client.send(ChannelsResquest(lastId: lastId)) { result in self.lastId = result!.items.last?.id self.hasNext = result!.hasNext self.data = result.items self.tableView.reloadData() } } }}
![Page 88: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/88.jpg)
extension ChannelsTableViewController: UITableViewDelegate { override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { if indexPath.row == data.count - 1 { load() }}
![Page 89: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/89.jpg)
...
![Page 90: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/90.jpg)
...
private var isLoading = false
func load() { if isLoading { return } if hasNext { isLoading = true client.send(ChannelsResquest(lastId: lastId)) { result in //... self.isLoading = false } }}
![Page 91: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/91.jpg)
ChannelsTableViewController
Pagina&on<Channel>
![Page 92: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/92.jpg)
FriendsTableViewController
Pagina&on<Friend>
![Page 93: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/93.jpg)
![Page 94: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/94.jpg)
![Page 95: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/95.jpg)
![Page 96: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/96.jpg)
BaseTableViewController
![Page 97: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/97.jpg)
class BaseTableViewController: UITableViewController { var lastId: Int? = nil var hasNext = true var isLoading = false
func loadNext() { if isLoading { return } if hasNext { isLoading = true doLoad {result in self.lastId = //... self.hasNext = //... } } }
func doLoad(handler: (Any?)->Void) { // ?? }}
![Page 98: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/98.jpg)
class BaseTableViewController: UITableViewController { var lastId: Int? = nil var hasNext = true var isLoading = false
func loadNext() { if isLoading { return } if hasNext { isLoading = true doLoad {result in self.lastId = //... self.hasNext = //... } } }
func doLoad(handler: (Any?)->Void) { fatalError("You should implement it in subclass!") }}
![Page 99: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/99.jpg)
class FriendsTableViewController: BaseTableViewController { private var data: [Friend] = []
override func viewDidLoad() { super.viewDidLoad() loadNext() }
override func doLoad(handler: (Any?)->Void) { client.send(FriendsRequest(lastId: lastId)) { result in handler(result) // ... self.data = result!.items self.tableView.reloadData() } }}
![Page 100: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/100.jpg)
![Page 101: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/101.jpg)
![Page 102: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/102.jpg)
WTF?
![Page 103: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/103.jpg)
• FriendsTableViewController → FriendsCollec5onViewController
![Page 104: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/104.jpg)
• FriendsTableViewController → FriendsCollec5onViewController
• BaseTableViewController → BaseCollec5onViewController
![Page 105: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/105.jpg)
• FriendsTableViewController → FriendsCollec5onViewController
• BaseTableViewController → BaseCollec5onViewController
?
![Page 106: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/106.jpg)
• FriendsTableViewController → FriendsCollec5onViewController
• BaseTableViewController → BaseCollec5onViewController
![Page 107: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/107.jpg)
![Page 108: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/108.jpg)
struct NextPageState<T> { private(set) var hasNext: Bool private(set) var isLoading: Bool private(set) var lastId: T?
init() { hasNext = true isLoading = false lastId = nil }
mutating func reset() { hasNext = true isLoading = false lastId = nil }
mutating func update(hasNext: Bool, isLoading: Bool, lastId: T?) { self.hasNext = hasNext self.isLoading = isLoading self.lastId = lastId }}
![Page 109: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/109.jpg)
protocol NextPageLoadable: class { associatedtype DataType associatedtype LastIdType
var data: [DataType] { get set } var nextPageState: NextPageState<LastIdType> { get set } func performLoad( successHandler: (_ rows: [DataType], _ hasNext: Bool, _ lastId: LastIdType?) -> (), failHandler: () -> () )}
![Page 110: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/110.jpg)
protocol NextPageLoadable: class { associatedtype DataType associatedtype LastIdType
var data: [DataType] { get set } var nextPageState: NextPageState<LastIdType> { get set } func performLoad( successHandler: (_ rows: [DataType], _ hasNext: Bool, _ lastId: LastIdType?) -> (), failHandler: () -> () )}
extension NextPageLoadable where Self: UITableViewController { func loadNext() { guard nextPageState.hasNext else { return } if nextPageState.isLoading { return }
![Page 111: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/111.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() { guard nextPageState.hasNext else { return } if nextPageState.isLoading { return }
nextPageState.isLoading = true performLoad(successHandler: { rows, hasNext, lastId in self.data += rows self.nextPageState.update(hasNext: hasNext, isLoading: false, lastId: lastId)
![Page 112: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/112.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() { guard nextPageState.hasNext else { return } if nextPageState.isLoading { return }
nextPageState.isLoading = true performLoad(successHandler: { rows, hasNext, lastId in self.data += rows self.nextPageState.update(hasNext: hasNext, isLoading: false, lastId: lastId)
self.tableView.reloadData()
}, failHandler: { //.. }) }}
![Page 113: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/113.jpg)
class FriendTableViewController: UITableViewController { var nextPageState = NextPageState<Int>() var data: [Friend] = []}
extension FriendTableViewController: NextPageLoadable { func performLoad( successHandler: ([String], Bool, Int?) -> (), failHandler: () -> ()) { client.send(FriendsRequest()) { result in if let result = result { successHandler(result.items, result.hasNext, result.items.last.id) } else { failHandler() } } }}
![Page 114: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/114.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() { ... }}
![Page 115: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/115.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() { ... }}
extension FriendTableViewController: NextPageLoadable { ... }class FriendTableViewController: UITableViewController { //... override func viewDidLoad() { super.viewDidLoad() loadNext() }
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { if indexPath.row == data.count - 1 { loadNext() } }}
![Page 116: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/116.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() { ... }}
UICollec(onView
![Page 117: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/117.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() { ... }}
UICollec(onView
extension NextPageLoadable where Self: UICollectionViewController { func loadNext() { ... }}
![Page 118: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/118.jpg)
Self: UITableViewController tableView.reloadData
extension NextPageLoadable where Self: UITableViewController { func loadNext() { guard nextPageState.hasNext else { return } if nextPageState.isLoading { return }
nextPageState.isLoading = true performLoad(successHandler: { rows, hasNext, lastId in self.data += rows self.nextPageState.update(hasNext: hasNext, isLoading: false, lastId: lastId)
self.tableView.reloadData()
}, failHandler: { // Failed when first loading if self.nextPageState.lastId == nil { self.data = [] self.nextPageState.reset() } }) }}
![Page 119: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/119.jpg)
tableView.reloadData()colletionView.reloadData()
![Page 120: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/120.jpg)
tableView.reloadData()colletionView.reloadData()
protocol ReloadableType { func reloadData()}
extension UITableView: ReloadableType {}extension UICollectionView: ReloadableType {}
![Page 121: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/121.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() {
//...
self.tableView.reloadData()
//... }}
![Page 122: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/122.jpg)
extension NextPageLoadable {
func loadNext(view: ReloadableType) {
//...
view.reloadData()
//... }}
![Page 123: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/123.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() { loadNext(reloadView: tableView) }}
![Page 124: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/124.jpg)
extension NextPageLoadable where Self: UITableViewController { func loadNext() { loadNext(reloadView: tableView) }}
extension NextPageLoadable where Self: UICollectionViewController { func loadNext() { loadNext(reloadView: collectionView) }}
![Page 125: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/125.jpg)
• FriendsTableViewController → FriendsCollec5onViewController
![Page 126: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/126.jpg)
class FriendTableViewController: UITableViewController { var nextPageState = NextPageState<Int>() var data: [Friend] = []}
extension FriendTableViewController: NextPageLoadable { func performLoad( successHandler: ([String], Bool, Int?) -> (), failHandler: () -> ()) { client.send(FriendsRequest()) { result in if let result = result { successHandler(result.items, result.hasNext, result.items.last.id) } else { failHandler() } } }}
![Page 127: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/127.jpg)
class FriendCollectionViewController: UITableViewController { var nextPageState = NextPageState<Int>() var data: [Friend] = []}
extension FriendCollectionViewController: NextPageLoadable { func performLoad( successHandler: ([String], Bool, Int?) -> (), failHandler: () -> ()) { client.send(FriendsRequest()) { result in if let result = result { successHandler(result.items, result.hasNext, result.items.last.id) } else { failHandler() } } }}
![Page 128: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/128.jpg)
NextPageState performLoad Request performLoad
ViewController
![Page 129: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/129.jpg)
ViewController
• ViewController ( )
![Page 130: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/130.jpg)
ViewController
• ViewController ( )
• ViewController
![Page 131: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/131.jpg)
ViewController
• ViewController ( )
• ViewController
• ViewController
![Page 132: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/132.jpg)
ViewController
• ViewController ( )
• ViewController
• ViewController
•
![Page 133: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/133.jpg)
・陪伴
![Page 134: U è Cocoa 1 Jpic.huodongjia.com/ganhuodocs/2017-06-19/1497852638.79.pdf · Swift ½ u * þ M 50 Z û T e ç Þ 1 ~ M 1 + , ó · ÿ Q 1 6protocol Swift Í z 1 , 7 Í z 1 L \ ± Á](https://reader034.fdocuments.us/reader034/viewer/2022050418/5f8de8215926372615373067/html5/thumbnails/134.jpg)
• Protocol-Oriented Programming in Swi4 - WWDC 15 #408
• Protocols with Associated Types - @alexisgallagher
• Protocol Oriented Programming in the Real World - @_maHhewpalmer
• PracIcal Protocol-Oriented-Programming - @natashatherobot