Swift3 0 空間命名

2021-09-12 09:49:40 字數 1940 閱讀 3732

swift3.0 - 真的很簡單

swift3.0 - 資料型別

swift3.0 - array

swift3.0 - 字典

swift3.0 - 可選值

swift3.0 - 集合

swift3.0 - 流控制

swift3.0 - 物件和類

swift3.0 - 屬性

swift3.0 - 函式和閉包

swift3.0 - 初始化和釋放

swift3.0 - 協議protocol

swift3.0 - 類和結構體的區別

swift3.0 - 列舉

swift3.0 - 擴充套件

swift3.0 - 下標

swift3.0 - 泛型

swift3.0 - 異常錯誤

swift3.0 - 斷言

swift3.0 - 自動引用計數(strong,weak,unowned)

swift3.0 - 檢測api

swift3.0 - 物件的標識

swift3.0 - 注釋

swift3.0 - 元型別

swift3.0 - 空間命名

swift3.0 - 物件判等

swift3.0 - **self的用途

swift3.0 - 類簇

swift3.0 - 動態呼叫物件(例項)方法

swift3.0 - 文字輸出

swift3.0 - 黑魔法swizzle

swift3.0 - 映象

swift3.0 - 遇到的坑

如果你不想給類名加字首,然後又想避免出現類名衝突,這個時候,就可以使用它了

**示例

struct myclasscontrainer1

}}struct myclasscontrainer2

}}let student1 = myclasscontrainer1.student()

let student2 = myclasscontrainer1.student()

應用場景1:

我們想通知中心傳送一條訊息

notificationcenter.default.post(name: notification.name("socketconnectfailure"), object: ["errorcode":000])
我們註冊通知的寫法是下面這樣的

notificationcenter.default.addobserver(self, selector: #selector(socketconnectfailure(notification:)), name: notification.name("socketconnectfailure"), object: nil)
思考: 我們如果能夠更加直觀的知道socketconnectfailure 是哪一類訊息呢?

命名空間優雅的寫法

extension notification.name 

}

使用:

//   想通知中心post 訊息

notificationcenter.default.post(name: notification.name.sockettask.connectfailure, object: ["errorcode":000])

// 增加觀察者

notificationcenter.default.addobserver(self, selector: #selector(socketconnectfailure(notification:)), name: notification.name.sockettask.connectfailure, object: nil)

Swift3 0 建構函式

viewcontroller.swift import uikit 在swift中,同乙個專案中 同乙個命名空間 所有的類預設都是共享的,不需要引用,可以直接訪問,不需要import 所有物件的屬性 var,也可以直接訪問到 class viewcontroller uiviewcontroller...

Swift3 0 異常錯誤

swift3.0 真的很簡單 swift3.0 資料型別 swift3.0 array swift3.0 字典 swift3.0 可選值 swift3.0 集合 swift3.0 流控制 swift3.0 物件和類 swift3.0 屬性 swift3.0 函式和閉包 swift3.0 初始化和釋放...

swift3 0藍芽開發(1)

1 外設 指被手機藍芽連線的物件,準確的說是被中心裝置連線的物件 3 服務 每個外設都會有1到多個服務,每個服務負責不同的模組 類似對物件導向語言的類 4 特徵 每個服務下面都會有1到多個特徵,每個特徵負責不同的功能 類似於oc語言的屬性 5 uuid 服務和特徵都會有唯一的uuid,外設也會有唯一...