Skip to content

Commit 2c3cc23

Browse files
committed
First commit
0 parents  commit 2c3cc23

File tree

7 files changed

+245
-0
lines changed

7 files changed

+245
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Swift 讀書會
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='3.0' sdk='iphonesimulator'>
3+
<sections>
4+
<code source-file-name='section-1.swift'/>
5+
</sections>
6+
<timeline fileName='timeline.xctimeline'/>
7+
</playground>

chapter 01 - 04/MyPlayground.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,30 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Timeline
3+
version = "3.0">
4+
<TimelineItems>
5+
<LoggerValueHistoryTimelineItem
6+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=742&amp;EndingColumnNumber=6&amp;EndingLineNumber=21&amp;StartingColumnNumber=5&amp;StartingLineNumber=21&amp;Timestamp=489335250.84186"
7+
selectedRepresentationIndex = "0"
8+
shouldTrackSuperviewWidth = "NO">
9+
</LoggerValueHistoryTimelineItem>
10+
<LoggerValueHistoryTimelineItem
11+
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=742&amp;EndingColumnNumber=13&amp;EndingLineNumber=21&amp;StartingColumnNumber=1&amp;StartingLineNumber=21&amp;Timestamp=489335250.842033"
12+
selectedRepresentationIndex = "0"
13+
shouldTrackSuperviewWidth = "NO">
14+
</LoggerValueHistoryTimelineItem>
15+
<LoggerValueHistoryTimelineItem
16+
documentLocation = "#CharacterRangeLen=24&amp;CharacterRangeLoc=265&amp;EndingColumnNumber=25&amp;EndingLineNumber=10&amp;StartingColumnNumber=1&amp;StartingLineNumber=10&amp;Timestamp=489335332.910608"
17+
selectedRepresentationIndex = "0"
18+
shouldTrackSuperviewWidth = "NO">
19+
</LoggerValueHistoryTimelineItem>
20+
<LoggerValueHistoryTimelineItem
21+
documentLocation = "#CharacterRangeLen=12&amp;CharacterRangeLoc=730&amp;EndingColumnNumber=13&amp;EndingLineNumber=29&amp;StartingColumnNumber=1&amp;StartingLineNumber=29&amp;Timestamp=489335332.910608"
22+
selectedRepresentationIndex = "0"
23+
shouldTrackSuperviewWidth = "NO">
24+
</LoggerValueHistoryTimelineItem>
25+
<LoggerValueHistoryTimelineItem
26+
documentLocation = "#CharacterRangeLen=12&amp;CharacterRangeLoc=537&amp;EndingColumnNumber=13&amp;EndingLineNumber=22&amp;StartingColumnNumber=1&amp;StartingLineNumber=22&amp;Timestamp=489335332.910608"
27+
selectedRepresentationIndex = "0"
28+
shouldTrackSuperviewWidth = "NO">
29+
</LoggerValueHistoryTimelineItem>
30+
</TimelineItems>
31+
</Timeline>

chapter 01 - 04/README.md

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
![Quick Help](http://i.imgur.com/axlV2ij.png)
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+
![code explaination](http://i.imgur.com/tviBqSL.png)
134+
135+
---
136+
137+
# UIControlEvent
138+
139+
![UIControlEvent](http://i.imgur.com/IOpCeAc.png)
140+
141+
---
142+
143+
# Target-Action
144+
145+
![target-action](http://i.imgur.com/BweCg86.jpg)
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`

0 commit comments

Comments
 (0)