原文:https://www.raywenderlich.com/126365/ios-frameworks-tutorial
frameworks 的三個(gè)主要作用
- 代碼封閉
- 代碼模塊化
- 代碼復(fù)用
開始
創(chuàng)建 Framework
- Xcode -> new -> Project -> iOS Framework & Library-> Cocoa Touch Framework.
- 填寫相應(yīng)的 Product Name, Organization Name等胆剧。
-
拖入相關(guān)的Code及資源文件。
- 添加到工程項(xiàng)目中(可選)
-
添加frameworks 到 Embedded Binaries中
Access Control(訪問控制)
Swift有三種訪問控制:
- Public: for code called by the app or other frameworks, e.g., a custom view.
- Internal: for code used between functions and classes within the framework, e.g., custom layers in that view.
- Private: for code used within a single file, e.g., a helper function that computer layout height.
Update the Storyboard
In the Identity Inspector, under Custom Class, change the Module to ThreeRingControl.