Skip to content

Commit 76388f8

Browse files
committed
added optional protocol methods
1 parent 30b5937 commit 76388f8

File tree

14 files changed

+455
-0
lines changed

14 files changed

+455
-0
lines changed

OptionalProtocolMethods/1.swift

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
protocol Route {
2+
func moveToHomeScreen()
3+
func moveToSettings()
4+
}
5+
6+
class IntroViewController: Route {
7+
func moveToHomeScreen() {
8+
// implementation
9+
}
10+
11+
func moveToSettings() {
12+
// implementation
13+
}
14+
}
15+
16+
class HomeViewController: Route {
17+
// not required in this case
18+
func moveToHomeScreen() {
19+
// implementation
20+
}
21+
22+
func moveToSettings() {
23+
// implementation
24+
}
25+
}

OptionalProtocolMethods/2.swift

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
protocol Route {
3+
func moveToHomeScreen()
4+
func moveToSettings()
5+
}
6+
7+
extension Route {
8+
func moveToHomeScreen() {
9+
// implementation
10+
}
11+
}
12+
13+
class IntroViewController: Route {
14+
func moveToHomeScreen() {
15+
// implementation
16+
}
17+
18+
func moveToSettings() {
19+
// implementation
20+
}
21+
}
22+
23+
class HomeViewController: Route {
24+
// not required in this case
25+
26+
27+
func moveToSettings() {
28+
// implementation
29+
}
30+
}
31+
32+
33+
34+
35+
36+
//@objc protocol Route {
37+
// @objc optional func moveToHomeScreen()
38+
// func moveToSettings()
39+
//}
40+
//
41+
//class IntroViewController: Route {
42+
// func moveToHomeScreen() {
43+
// // implementation
44+
// }
45+
//
46+
// func moveToSettings() {
47+
// // implementation
48+
// }
49+
//}
50+
//
51+
//class HomeViewController: Route {
52+
// func moveToSettings() {
53+
// // implementation
54+
// }
55+
//}
56+

OptionalProtocolMethods/3.swift

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@objc protocol Route {
2+
@objc optional func moveToHomeScreen()
3+
func moveToSettings()
4+
}
5+
6+
class IntroViewController: Route {
7+
func moveToHomeScreen() {
8+
// implementation
9+
}
10+
11+
func moveToSettings() {
12+
// implementation
13+
}
14+
}
15+
16+
class HomeViewController: Route {
17+
func moveToSettings() {
18+
// implementation
19+
}
20+
}

OptionalProtocolMethods/4.swift

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
protocol HomeRoute {
2+
func moveToHomeScreen()
3+
}
4+
5+
protocol SettingsRoute {
6+
func moveToSettings()
7+
}
8+
9+
class IntroViewController: HomeRoute, SettingsRoute {
10+
func moveToHomeScreen() {
11+
// implementation
12+
}
13+
14+
func moveToSettings() {
15+
// implementation
16+
}
17+
}
18+
19+
class HomeViewController: SettingsRoute {
20+
func moveToSettings() {
21+
// implementation
22+
}
23+
}
24+
25+
8.62 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import UIKit
2+
3+
print("Optional protocol methods")
4+
//protocol Route {
5+
// func moveToHomeScreen()
6+
// func moveToSettings()
7+
//}
8+
//
9+
//class IntroViewController: Route {
10+
// func moveToHomeScreen() {
11+
// // implementation
12+
// }
13+
//
14+
// func moveToSettings() {
15+
// // implementation
16+
// }
17+
//}
18+
//
19+
//class HomeViewController: Route {
20+
// // not required in this case
21+
// func moveToHomeScreen() {
22+
// // implementation
23+
// }
24+
//
25+
// func moveToSettings() {
26+
// // implementation
27+
// }
28+
//}
29+
30+
31+
32+
33+
34+
35+
//protocol Route {
36+
// func moveToHomeScreen()
37+
// func moveToSettings()
38+
//}
39+
//
40+
//extension Route {
41+
// func moveToHomeScreen() {
42+
// // implementation
43+
// }
44+
//}
45+
//
46+
//class IntroViewController: Route {
47+
// func moveToHomeScreen() {
48+
// // implementation
49+
// }
50+
//
51+
// func moveToSettings() {
52+
// // implementation
53+
// }
54+
//}
55+
//
56+
//class HomeViewController: Route {
57+
// // not required in this case
58+
// func moveToHomeScreen() {
59+
// // implementation
60+
// }
61+
//
62+
// func moveToSettings() {
63+
// // implementation
64+
// }
65+
//}
66+
67+
68+
69+
70+
71+
//@objc protocol Route {
72+
// @objc optional func moveToHomeScreen()
73+
// func moveToSettings()
74+
//}
75+
//
76+
//class IntroViewController: Route {
77+
// func moveToHomeScreen() {
78+
// // implementation
79+
// }
80+
//
81+
// func moveToSettings() {
82+
// // implementation
83+
// }
84+
//}
85+
//
86+
//class HomeViewController: Route {
87+
// func moveToSettings() {
88+
// // implementation
89+
// }
90+
//}
91+
92+
93+
94+
95+
protocol HomeRoute {
96+
func moveToHomeScreen()
97+
}
98+
99+
protocol SettingsRoute {
100+
func moveToSettings()
101+
}
102+
103+
class IntroViewController: HomeRoute, SettingsRoute {
104+
func moveToHomeScreen() {
105+
// implementation
106+
}
107+
108+
func moveToSettings() {
109+
// implementation
110+
}
111+
}
112+
113+
class HomeViewController: SettingsRoute {
114+
func moveToSettings() {
115+
// implementation
116+
}
117+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>

OptionalProtocolMethods/OptionalProtocolMethods.playground/playground.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>OptionalProtocolMethods (Playground).xcscheme</key>
8+
<dict>
9+
<key>isShown</key>
10+
<false/>
11+
<key>orderHint</key>
12+
<integer>0</integer>
13+
</dict>
14+
</dict>
15+
</dict>
16+
</plist>

0 commit comments

Comments
 (0)