# iOS Interview Questions
### What are the major differences between Swift and Objective-C?
It's different with these two laguanges besides they're both references counted, but I think the major differents is message dispatch, Objective-C use SEL name to calling objc_msgSend in object's method list, Swift lookup function pointer in vtable with index.
[Reference](https://blog.untitledkingdom.com/objective-c-vs-swift-messages-dispatch-9d5b7fd58327)
### What differences between http and https
https is based on http but with encrypted with SSL/TLS.
### What kind of things should be write in ViewModel
The logic that communicates between UI and model (or server).
### What kind of things shouldn't be write in ViewModel
The logic that based on user interface instance.
### What should the ViewModel tests have
It depends. For me I'll test all inputs and outputs if I could.
### 當 Protocol 有一個 function,而寫一個 Extension 去補足這個 function 的實作,為什麼要這樣做
To support optional protocol function in Swift
### 如何處理圓角問題
`layer.cornerRadius`
### 舉個 Protocol + associatedtype 的例子
`RawRepresentable`
### 怎麼在 Protocol 裡頭存取變數
What's that mean?
- Objective-C method swizzling 的運作原理
### Swift 上如何實作 method swizzling
[Reference](https://medium.com/@abhimuralidharan/method-swizzling-in-ios-swift-1f38edaf984f)
- 解釋 FRP 和舉個使用情境
- 解釋 KVO 以及其背後的原理是什麼
- Swift 上的 map 要如何實作
- 若你設計 map,你會怎麼設立 parameter
- ARC 和 MRC 的差異,ARC 的 Automatic 做了什麼事
- class 和 struct 之間的差異
- class 和 struct 分別存在記憶體哪個位置
- 什麼時候使用 class、什麼時候使用 sturct
- 什麼時候 value-type 會 copy 一份
### Escaping Closures
closure is said to escape a function when the closure is passed as an argument to the function, but is called after the function returns. When you declare a function that takes a closure as one of its parameters, you can write @escaping before the parameter’s type to indicate that the closure is allowed to escape.
(for example: store clsoures as a property)
```swift
var completionHandlers: [() -> Void] = []
func someFunctionWithEscapingClosure(completionHandler: @escaping () -> Void) {
completionHandlers.append(completionHandler)
}
```
- launch time 怎麼優化
- 解釋 app 啟動的流程
- 解釋一下 MachO
- 如何抓到 https 的請求和 response
- 如何避免被抓包
- 後端如何使用 https 的方式來保證前端來源是允許的
- 解釋一個請求的流程,從前端打到一個網域,接著是如何最後抵達相對應的機器(IP)
- process 和 thread 的差異
- 舉個造成 thread dead-lock 的例子
- 解釋一下 runloop 的各個 mode
- NSOpeartion 和 DispatchQueue 的差異
- 同時下載很多資源時,如何取消其中一個 DispatchQueue
- 如何壓縮圖片到指定的大小
- 解釋 Off-Screen rendering
- 解釋 POP 和 FRP
- 解釋 MVC 和 MVVM 差異
- 解釋 Coordinator 架構
- 那若當某個 struct 自己又實作了一次這個 function,會執行哪一個?
- 如果是 class 的話,會執行哪一個?為什麼?
- TableView 的卡頓有哪些狀況、如何解決
- 解釋 EXC_BAD_ACCESS
## Personalized Questions
- 有沒有使用過抓包軟體
- 有沒有使用過 runtime