Data Types
- String
- Int ( Integer )
- Float
- Double
- Bool ( Boolean )
Random methods
// Int.random(in: lower ... upper)
Int.random(in: 1 ... 5) // including Integer 1 to 5
Int.random(in: 1 ..< 5) // including Integer 1 to 4
/* Also can use in Float
Float.random(in: lower ... upper)
*/
/* Boolean use random generator
Bool.random()
*/
/* Array for random element
Array.randomElement()
Array.shuffle() -> for rerandom the array
*/
AutoLayout
Add New Constraints 可設置背景圖完全擴展,使螢幕翻轉不影響。
若要置中,使用 Add New Alignment Constraints,並勾選 Horizontally in Container、Vertically in Container。
若水平置中,且與上方物件距離 30 pixel,則 Horizontally in Container 打勾,並於 Add New Constraints 中選擇要對應的物件,並設置距離數值。
較複雜版面設置,需使用 UIView 去包裝多個元件,但 UIView 只是一個容器,無法確切知道你所需的佈局方向,故外層會需要使用 Stack View(Horizontally or Vertically) 去設置佈局方向。
Create a function
// create a function
/*
<func keyWord> <funcName>(<parameterName>: <parameterDataType> {
}
*/
func getMilk(bottles: Int) {
<whatToDo>
}
// call the function
/*
<methodName>(<parameter>: <argument>)
*/
getMilk(bottles: 2)
Xcode常用快捷鍵
Esc : 提示程式碼段落
Ctrl + . : 正向循環程式碼提示
Shift + Ctrl + . : 反向循環程式碼提示
Ctrl + K : 刪除本行
Option + codeName : 顯示interface文件