Content Hugging and Compression Resistance 都是1–1000之間的數字,當在stackView中,要決定哪個物件被壓縮/延展時的決定要件。物件之間的Content Hugging and Compression Resistance會被互相比較。

Content Hugging 越高(數字越大),越能用力抱住 …

非常簡化的解釋使用NotificationCenter的概念:

NotificationCenter的運作很像是一群黑道小弟闖入一間民宅,他們要把吃飯發出「滋滋滋」聲音的人打一打。所以只要黑道小弟這群「觀察者」聽到「滋滋滋」就會做「打人」的動作。

Step1.在Notification.Name新增事件名。(將滋滋滋事件取名)

Step2.addObse …

unwindSegue就是把segue倒轉,但不是在原本的segue上,而是要用程式碼新創一條segue。

大致來說有以下幾個步驟:

Step1: 新創segue。

Step2:選定要用新創segue。

Step3:將新創segue的segue identifier取名。

Step4:執行perform segue。

Step1: 在code檔案中撰寫新創segue …

filter()

reduce()/reduce(into:)

sort()/sort(by:)

sorted() /sorted(by:)

filter()

filter()有一個參數那個參數是closure,他做的事就是跑過collection,然後把collection中的item放入closure檢測,如果 return true 就把那個item加到return的值。

reduce()

可以設initial Value, result Value,然後跑array,把每次跑到的物件跟initial value 做互動 變為 result value。result value 每跑一次回圈都會自己update …

Trailing Closure

How closure dealing with collections

.forEach

.map return 成指定型別

.compactMap(_:)

flatMap(_:)

Trailing Closure

當closure是最後一個參數時,可以把closure移到小括號外。

How closure dealing with collections

collection有很多swift已經寫好的method用closure來對collection做各種動作。

.forEach

forEach — Loops over a collection and performs an operation

numbers.forEach{ number inprint(number)}

其實跟for in loop 做一樣的事

for number in numbers {print(number)}

.map

map — Loops over an array, executes closure code…

The difference between function and method

overloading — 名字一樣的function

Variadic Parameters

Inout Parameters

functions are data types

higher-order functions

typealias

The difference between function and method

雖然這兩個字時常被大家交替使用,但是最好還是用精準的用法,所以就來澄清一下它們兩者的不同。function也有人會叫free function。

function:Some may also call it “free function”, because it isn’t owned by a named type like a structure or a class.

method: Essentially function which belong to another…

Astrid

A Swift learner.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store