原创 swift的閉包

函數其實就是一種特殊的閉包。分爲三種情況: 全局函數:它是有名稱並不捕獲任何值得閉包。 嵌套函數:它是有名稱的閉包,可以從封閉的函數中波或值。 閉包表達式:它是無名稱的閉包,可以捕獲它上下文的值。 定義 The

原创 swift結構體常量的存儲屬性

If you create an instance of a structure and assign that instance to a constant, you cannot modify the instance’s p

原创 swift函數

1.無參數的函數 注意儘管不帶參數,但是我們在調用的時候還是要帶上空括號。這也體現了swift語言的準確性,它讓你的代碼必須表達明確 2.帶參數的函數 注意:函數裏邊的數組之類的並不進行類型檢查,運行時可能會崩潰。因

原创 swift函數的參數標籤和參數名稱

每個函數參數都具有參數標籤和參數名稱。參數標籤在調用函數時使用; 參數標籤寫在參數名稱前。參數名稱用於函數的實現。默認情況下,參數使用其參數名稱作爲其參數標籤。 省略參數標籤 如果不想要參數的參數標籤,請爲該參數編寫下劃線

原创 swift中的類型方法

定義 Instance methods, as described above, are methods that are called on an instance of a particular type. You can

原创 swift逃逸閉包

定義 A closure is said to escape a function when the closure is passed as an argument to the function, but is called

原创 swift類和結構體(一)

An instance of a class is traditionally known as an object. However, Swift classes and structures are much closer i

原创 swift結構體的mutating

Structures and enumerations are value types. By default, the properties of a value type cannot be modified from wit

原创 swift閉包的值捕獲

我們說嵌套函數其實也是一種特殊的閉包: 在第一次調用得到嵌套函數時,其實嵌套函數已經捕獲了在他之前定義的包括參數和局部變量等。以後這些值如果需要進行改變的話,進行的是引用的改變。 注意 第二次重新得到新的嵌套函數與第一次

原创 swift字典

1.創建空字典 var dic = Int:String let name = [“sex”:”男”] 2.判斷空 name.isEmpty 3.訪問和修改 3.1直接用下標 3.2利用更新方法 它有一個好處是會返回舊值。 4.

原创 swift中的self屬性

Every instance of a type has an implicit property called self, which is exactly equivalent to the instance itself

原创 swift的枚舉

An enumeration defines a common type for a group of related values and enables you to work with those values in a t

原创 字符串、數組和字典的賦值和複製

In Swift, many basic data types such as String, Array, and Dictionary are implemented as structures. This means tha

原创 自動閉包

定義 An autoclosure is a closure that is automatically created to wrap an expression that’s being passed as an argum

原创 函數類型

定義 函數類型由參數類型和函數的返回組成。 這兩個函數的類型是:(Int,Int)->Int 這個函數的類型是:()->Void 函數類型變量 函數類型和其他的數據類型沒有區別。你可以以用函數類型來定義常量或者變