├── .gitignore
├── README.md
├── chapter 01 - 04
├── MyPlayground.playground
│ ├── contents.xcplayground
│ ├── playground.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ │ └── diuitPo.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ ├── section-1.swift
│ └── timeline.xctimeline
└── README.md
├── chapter 05 - 06
└── README.md
├── chapter 07 - 08
├── README.md
├── chapter7_1.png
├── chapter7_2.png
├── chapter7_3.png
├── chapter7_4.png
├── chapter7_5.png
├── chapter8_1.png
└── slide.html
└── chapter 11 - 12
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Swift 讀書會
2 |
3 |
--------------------------------------------------------------------------------
/chapter 01 - 04/MyPlayground.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/chapter 01 - 04/MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/chapter 01 - 04/MyPlayground.playground/playground.xcworkspace/xcuserdata/diuitPo.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softnshare/swift/6e78b5f8ba0733a14adda272253d7ae786c5488e/chapter 01 - 04/MyPlayground.playground/playground.xcworkspace/xcuserdata/diuitPo.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/chapter 01 - 04/MyPlayground.playground/section-1.swift:
--------------------------------------------------------------------------------
1 | // Playground - noun: a place where people can play
2 |
3 | // You need import this for `UILabel`
4 | import UIKit
5 |
6 | var str = "Hello, playground"
7 |
8 | var message1 = "Hello Swift! How can I get started?"
9 | var message2 = "The best way to get started is to stop talking and code."
10 |
11 | message1.uppercaseString
12 | message2.lowercaseString + " Okay, I'm working on it 😐"
13 |
14 | if message1 == message2 {
15 | print("Same message")
16 | } else {
17 | print("Not the same message")
18 | }
19 |
20 | let messageLabel = UILabel(frame: CGRectMake(0, 0, 300, 50))
21 | messageLabel.text = message1
22 |
23 | messageLabel
24 |
25 | messageLabel.backgroundColor = UIColor.orangeColor()
26 | messageLabel.textAlignment = NSTextAlignment.Center
27 |
28 | messageLabel.layer.cornerRadius = 10.0
29 | messageLabel.clipsToBounds = true
30 | messageLabel
31 |
--------------------------------------------------------------------------------
/chapter 01 - 04/MyPlayground.playground/timeline.xctimeline:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
10 |
14 |
15 |
19 |
20 |
24 |
25 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/chapter 01 - 04/README.md:
--------------------------------------------------------------------------------
1 | # Swift 讀書會 Week 1
2 |
3 | * Chp 1 - 環境設定
4 | * Chp 2 - Playground 教學
5 | * Chp 3 - 第一個APP 與Xcode環境認識
6 | * Chp 4 - 第一個APP的運作原理
7 |
8 | ---
9 |
10 | # 操作環境
11 |
12 | * OS X 10.11.5
13 | * Xcode 7.3.1
14 | * Swift 2.2 (Xcode 7.3.1 Default)
15 |
16 | ---
17 |
18 | # Chapter 1
19 |
20 | 工具準備:
21 | 1. 一台Mac
22 | 2. 將你的Apple id[註冊](https://developer.apple.com/register/)為開發者帳號(如果你想在實機上run app)
23 | 3. 從App Store 安裝Xcode最新版(此文件中為7.3.1)
24 | 4. 如果想上架App,才需要Devloper program(一年 $99 美金)
25 |
26 | ---
27 |
28 | # Chpater 2
29 |
30 | 從Objective C說起:
31 | ```
32 | [self transitionFromViewController: firstVC toViewController: secondVC duration: 1.5 options: UIViewAnimationOptionRepeat animations: ^() { // do animation } completion: nil];
33 | ```
34 | * 語法起源於「small talk」
35 | * 超長的命名
36 | * **必須**宣告每個變數與常數的型態
37 | * 屬於「動態語言」(OS 10.5 之後)
38 |
39 | ---
40 |
41 | # Swift的野望
42 |
43 | * 追求更快,更現代,更安全的程式語言
44 | * 是一個「靜態語言」(Statically Typed Language)
45 | * 不一定要宣告變數型態(Type Inference)
46 | * 吸收JS, Python 等現代語言的優點
47 | * Optional的觀念,用於處理null(在Swift和OC用 `nil` )
48 |
49 | ---
50 |
51 | # 語法比一比
52 |
53 | ```objc
54 | const int count = 10;
55 | double price = 23.55;
56 |
57 | NSString *firstMessage = @"Swift is awesome. ";
58 | NSString *secondMessage = @"What do you think?";
59 | NSString *message = [NSString stringWithFormat:@"%@%@", firstMessage, secondMessage];
60 |
61 | NSLog(@"%@", message);
62 | NSLog([firstMessage isEqualToString: secondMessage] ? @"YES": @"NO");
63 | ```
64 |
65 | ```swift
66 | let count = 10
67 | var price = 23.55
68 |
69 | let firstMessage = "Swift is awesome. "
70 | let secondMessage = "What do you think?"
71 | var message: String = firstMessage + secondMessage
72 |
73 | print(message)
74 | print(firstMessage == secondMessage)
75 | ```
76 |
77 | ---
78 |
79 | # 通用的命名法則
80 |
81 | * `UIViewController`: UI (framework縮寫,此為UIKit) + ViewController(型別名稱)
82 | * 型別命名使用 upper camel case,例:`NSString`
83 | * property命名使用 lower camel case,例:`firstMessage`
84 |
85 | ---
86 |
87 | # 可變與不可變
88 |
89 | In Objectiv-C:
90 |
91 | * `NSArray` v.s. `NSMutableArray`
92 | * Mutable 代表本身可變
93 |
94 | In Swift:
95 |
96 | * let:常數不可變(但若指向一個reference type對象,則對象內成員可變)
97 | * var:本身為可變
98 |
99 | ```swift
100 | let str = "abcd"
101 | str = "efgh" // 此行Compiler會丟error警告
102 | ```
103 |
104 | ---
105 |
106 | # Playground
107 |
108 | * 顧名思義,試語法的地方
109 | * 類似Python或Javascript的 shell和console
110 | * 每打一個字就compile & run
111 | * [Demo範例檔]()
112 | * [Swift 2 basic tutorial 範例](https://www.dropbox.com/s/8kgxig3cgr4z2v4/SwiftIntro.zip?dl=0)
113 |
114 | ---
115 |
116 | # 小撇步
117 | 1. 在變數上按住「alt + 左鍵」點擊變數,會出現變數型別與宣告處
118 | 2. 在變數上按住「command + 左鍵」點擊變數,會跳到宣告變數的地方
119 | 3. 游標停留在型態宣告的地方,打開右側Utilites欄位,會出現Quick Help並顯示文件
120 | 
121 |
122 | ---
123 |
124 | # Chapter 3
125 |
126 | [Demo 程式檔](https://www.dropbox.com/s/m5ayco4iatiba8e/HelloWorld.zip?dl=0)
127 | [Xcode環境介紹](https://itisjoe.gitbooks.io/swiftgo/content/more/interface_intro.html)
128 |
129 | ---
130 |
131 | # Chpater 4
132 |
133 | 
134 |
135 | ---
136 |
137 | # UIControlEvent
138 |
139 | 
140 |
141 | ---
142 |
143 | # Target-Action
144 |
145 | 
146 |
147 | ---
148 |
149 | # Target-Action
150 |
151 | * Target: `ViewController`
152 | * Action: `helloMessage()` (由 TouchUpInside 啟動)
153 |
154 | ---
155 |
156 | # self
157 |
158 | * 代表現在(本身)這個instance 或 object
159 | * 在Swift中,大多時候可以省略(但要清楚到底是 property 或 local variable)
160 | * Capturing: 在Closure裡,不可以省略self(compiler會叫),另需特別處理以免發生retain cycle(closure時再說明)
161 |
162 | ---
163 |
164 | # 執行App
165 |
166 | 1. compile: Swift為靜態語言,大多數行為在此確定,將code編譯為machine code
167 | 2. package: 其實也算compile的一個階段,將各種資源(images, text)
168 | 3. run: 在simulator上執行,程式的進入點為 `AppDelegate.swift`
169 |
170 |
171 |
172 | ---
173 |
174 |
175 |
176 | # 額外討論-Optional
177 |
178 |
179 |
180 | * 一種宣告變數的型態( Int? != Int)
181 |
182 | * 內容其實是一個enum,代表這個變數有可能為null,例
183 |
184 | ```swift
185 | var a: Int? = nil
186 | var message: String! = "This varriable always has a value" // You know message always have a value
187 | var notNil: String = nil // 這行compiler會報錯
188 | ```
189 |
190 | * 打開optional(Unwrapp)
191 |
192 | * 使用 `!` 來打開一個optional,因為當optional變數被當做參數時,它實際不是任何Int, String等的型態,method不會接受(除非該method宣告為接受 optional變數當參數);但若打開到 nil,會直接runtime error。
193 |
194 | ```swift
195 | var a: Int? = 9
196 | var intArray: [Int] = [1,2]
197 | // append()只接受Int
198 | intArray.append(a!)
199 | ```
200 |
201 | * 或用 `let`來判斷optinal有沒有值
202 |
203 | ```swift
204 | var nullVar: String? = nil
205 | // 假裝我們不知道nullVar是nil
206 | if let str = nullVar {
207 | // nullVar如果有值會進到這裡
208 | print(str)
209 | } else {
210 | // 但實際沒有,會走這裡
211 | print("this var is nil")
212 | }
213 | ```
214 |
215 | * `guard` 是用在更易讀的code structure(相較 if … else …之下),可想做是不會中斷程式的`assert`,下面各是用if-else與guard的寫法
216 |
217 | ```swift
218 | // we don't want arg to be nil in this function
219 |
220 | // if else case
221 | func someFunc0(arg: Int?) {
222 | if arg == nil {
223 | print("arg is nil. We don't like it so do nothing")
224 | return
225 | } else {
226 | // 以下可以放心使用 arg! 而不crash了
227 | // ...
228 | }
229 | }
230 |
231 | // guard case
232 | func someFunc1(arg: Int?) {
233 | guard let _ = arg else {
234 | print("arg is nil. We do not like it so do nothing")
235 | return // guard裡一定要以 return or break等結尾
236 | }
237 |
238 | // 以下可以放心使用 arg! 而不crash了
239 | }
240 | ```
241 |
242 | * Implicit unwrapped optional: 如果你**確定一變數在access時總是有值**,可以用這種方式來宣告optional,免去判讀為nil的程式碼,為了讓程式碼更簡潔(在減少一些安全性的程度下)
243 |
244 | ```swift
245 | let possibleString: String? = "An optional string."
246 | let forcedString: String = possibleString! // requires an exclamation mark
247 |
248 | let assumedString: String! = "An implicitly unwrapped optional string."
249 | let implicitString: String = assumedString // no need for an exclamation mark
250 |
251 | let iCantBeNil: Int! = nil // This is OK for compilor, but you will die in runtime.
252 | ```
253 |
254 | * Optional Chaining: 可視為一種替代打開optional的方式
255 |
256 | ```swift
257 | class Person {
258 | var residence: Residence?
259 | }
260 |
261 | class Residence {
262 | var numberOfRooms = 1
263 | }
264 |
265 | let john = Person()
266 | // 下面這行會GG,因為residence 為 nil
267 | let roomCount = john.residence!.numberOfRooms
268 |
269 | // 只好檢查一下,但我不想把residence unwrapp再去access numberOfRooms
270 | if let roomCount = john.residence?.numberOfRooms {
271 | print("John's residence has \(roomCount) room(s).")
272 | } else {
273 | print("Unable to retrieve the number of rooms.")
274 | }
275 |
276 | // 給residence 值
277 | john.residence = Residence()
278 |
279 | // 安心上路
280 | print("John's residence has \(john.residence!.numberOfRooms) room(s).")
281 | ```
282 |
283 |
284 |
285 | ### Reference
286 |
287 | * [Swift 官方教學-Optionals](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID309)
288 | * [愛恨交織的optional](http://www.appcoda.com.tw/swift-optional/)
--------------------------------------------------------------------------------
/chapter 05 - 06/README.md:
--------------------------------------------------------------------------------
1 | # Swift 讀書會 Week 2
2 | * Chp 5 - Auto Layout的介紹
3 | * Chp 6 - 使用堆疊視圖設計UI
4 |
5 | ---
6 |
7 | # Auto Layout的介紹
8 |
9 | * Auto Layout是一個以約束條件為基礎的佈局系統(constraint-based layout system)
10 | * 它讓開發者能夠開發一個能自我調整型的UI,可以依照螢幕的尺寸以及裝置的方向來調整。
11 |
12 | ---
13 |
14 | # 現行iPhone各機型規格
15 | 
16 |
17 | ---
18 |
19 | * 2007,Apple推出的最原始iPhone,3.5英吋、320×480像素的畫面解析度的顯示器。
20 |
21 | * 之後Apple推出了iPhone 4搭配視網膜(retina)顯示器。畫面的解析度變成兩倍到640×960像素。也就是一個點相對應兩個像素。
22 |
23 | * 這些點與像素間的轉換工作,則由iOS處理。
24 |
25 | ---
26 |
27 | * 以Hello World按鈕為例,如果要把它擺在視圖中間應會得到兩個約束條件:
28 | 水平置中
29 | 垂直置中
30 | 這些約束條件顯示了按鈕在介面中的佈局。
31 |
32 | ---
33 |
34 | # 啟動尺寸類別
35 | * 檔案檢閱器(File Inspector)中,勾選「Use Size Classes」功能來啟動它。提示出現後,點選「Enable Size Classes」來確認這個變更
36 |
37 | ---
38 |
39 | # 兩種定義Auto Layout的方式
40 |
41 | * Auto Layout選單。
42 | * Control鍵加上拖曳。
43 |
44 | * 
45 |
46 | 每一個按鈕有它自己的功能:
47 |
48 | Align – 建立對齊的約束條件,例如:對齊兩個視圖的左側。
49 | Pin – 建立間距的約束條件,例如:訂出UI控制的寬度。
50 | Issues – 解決佈局問題。
51 | Stack – 視圖嵌入至堆疊視圖(stack view)。堆疊視圖是Xcode 7的新功能。
52 |
53 | ---
54 |
55 | # 解決佈局約束條件問題
56 |
57 | * 當有任何的佈局問題,文件大綱視圖會顯示出一個紅/橘色的揭露箭頭(disclosure arrow),按下這個揭露箭頭,你會看見問題清單。
58 | * 介面建構器可以聰明地幫助我們解決佈局問題,點選問題旁邊的指示圖標,選取「Update Frame」選項,然後點選「Fix Misplacement」按鈕。按鈕便會移 到視圖中間。
59 | * 另一種解決佈局的方式-Issue,如下圖所示
60 | 
61 |
62 | ---
63 | # Storyboard預覽
64 | * Xcode 7中,它提供開發者預覽(Preview)功能,讓開發者可以直接在Xcode中可以取得UI的預覽圖。
65 |
66 | * 在介面建構器中,打開Assistant彈出式選單→Preview(1),按住option鍵,然後點選「Main.storyboard(Preview)」。
67 |
68 | * 點擊助理編輯器左下角的「+」按鈕來加入iOS裝置(例如:iPhone 4.7英吋)來閱覽。如果你想觀察在橫向方向的顯示狀態,只要點選旋轉按鈕即可。
69 |
70 | ---
71 |
72 | # 頂部與底部佈局導引
73 |
74 | * 底部佈局導引(Bottom Layout Guide)位置是以視圖底部為準
75 |
76 | * 頂部佈局導引(Top Layout Guide),則從視圖最上方往下設定20點距離,也就是狀態欄(status bar)的高度
77 |
78 | ---
79 |
80 | # Autolayout Sample
81 |
82 | * https://youtu.be/3xzVdvh8AA0
83 | * https://youtu.be/gEooGq4SsxI
84 |
85 | ---
86 |
87 | # 使用堆疊視圖設計UI
88 |
89 | * 堆疊視圖提供一個簡化的介面,以行或列來佈局視圖的集合。在Keynote或者是微軟的Power Point,你可以將多個物件群組起來,讓它們可以使用一個單一物件來移動或調整大小。堆疊視圖提供了一個非常相似的功能。
90 |
91 | * 這個堆疊視圖會管理它的子視圖(subview)的佈局,並且自動幫你採用佈局約束條件。這表示,這些子視圖準備適應各種不同螢幕尺寸。
92 |
93 | ---
94 |
95 | # StackView Sample
96 |
97 | * 排列方式
98 | UIStackViewDistributionFill -填滿StackView高度或寬度
99 | UIStackViewDistributionFillEqually -SubView平均分配高度或寬度
100 | UIStackViewDistributionFillProportionally -依據SubView高度或寬度分配
101 | UIStackViewDistributionEqualSpacing -SubView間之間距相等
102 | UIStackViewDistributionEqualCentering -SubView中心之間距相等
103 |
104 | * https://youtu.be/o8J1SIWHk2Q
105 | *
106 |
107 | ---
108 |
109 | # 上課影片
110 | * https://youtu.be/v1zvPIWxcfA
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/chapter 07 - 08/README.md:
--------------------------------------------------------------------------------
1 | # Swift 讀書會 Week 3
2 | - Chp 7 寫程式前的規劃(App原型設計)
3 | - Chp 8 建立一個簡單的表格App
4 | ---
5 |
6 | ## What's prototype?
7 | 1. 可以驗證並視覺化Idea的早期模型
8 | 2. 核心功能要可以展示出來
9 |
10 | ---
11 |
12 | ## Why prototype?
13 | - 用來溝通
14 | - 跟團隊成員、客戶、測試人員
15 |
16 | 
17 | ---
18 | # 先在紙上畫草圖吧
19 |
20 | - [這裏可以免費下載草稿紙](https://popapp.in/sketchpad/)
21 | ---
22 |
23 | 
24 |
25 | ---
26 |
27 | ## 使用POP來Prototyping
28 | ---
29 |
30 | - [POP的下載連結](https://itunes.apple.com/tw/app/pop-prototyping-on-paper./id555647796?mt=8)
31 |
32 | 
33 |
34 | ---
35 | - [POP的網站](https://popapp.in)
36 |
37 | 
38 | ---
39 | ## Hifi Prototyping:使用Pages
40 |
41 | 
42 |
43 | - [keynotopia網站](http://keynotopia.com)
44 |
45 | ---
46 | ## Hifi Prototyping:使用Framejs
47 |
48 | - [framejs網站](http://framerjs.com/gallery/)
49 |
50 | ---
51 |
52 | # 創建簡單的表格APP Demo - 1
53 |
54 | - 拉UI
55 |
56 | - https://youtu.be/Lv1Q8IFlS88
57 |
58 | ---
59 | # Datasource 與 delegate
60 |
61 | 
62 |
63 | ---
64 | # 創建簡單的表格APP Demo - 2
65 |
66 | - 整合資料及Controller
67 |
68 | - https://youtu.be/8sL4embvQEQ
69 |
70 | ---
71 | template: inverse
72 | # 謝謝大家
73 | ## John Liu
74 | ## twitter: @johnliu33
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/chapter 07 - 08/chapter7_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softnshare/swift/6e78b5f8ba0733a14adda272253d7ae786c5488e/chapter 07 - 08/chapter7_1.png
--------------------------------------------------------------------------------
/chapter 07 - 08/chapter7_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softnshare/swift/6e78b5f8ba0733a14adda272253d7ae786c5488e/chapter 07 - 08/chapter7_2.png
--------------------------------------------------------------------------------
/chapter 07 - 08/chapter7_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softnshare/swift/6e78b5f8ba0733a14adda272253d7ae786c5488e/chapter 07 - 08/chapter7_3.png
--------------------------------------------------------------------------------
/chapter 07 - 08/chapter7_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softnshare/swift/6e78b5f8ba0733a14adda272253d7ae786c5488e/chapter 07 - 08/chapter7_4.png
--------------------------------------------------------------------------------
/chapter 07 - 08/chapter7_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softnshare/swift/6e78b5f8ba0733a14adda272253d7ae786c5488e/chapter 07 - 08/chapter7_5.png
--------------------------------------------------------------------------------
/chapter 07 - 08/chapter8_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/softnshare/swift/6e78b5f8ba0733a14adda272253d7ae786c5488e/chapter 07 - 08/chapter8_1.png
--------------------------------------------------------------------------------
/chapter 07 - 08/slide.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Title
5 |
6 |
139 |
140 |
141 |
237 |
239 |
242 |
243 |
--------------------------------------------------------------------------------
/chapter 11 - 12/README.md:
--------------------------------------------------------------------------------
1 | # Swift 讀書會 Week 3
2 | - Chp 11
3 | - Chp 12
4 |
5 |
6 | 主講人
7 | 1.polo
8 | 2.大祐
9 | 3.YUYU CHEN
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------