如何声明公共接口,例如apple.另一种方法,隐藏实现

Hua*_*gzy 7 init swift

就像UILabel类一样:

class UILabel : UIView, NSCoding {

    var text: String! // default is nil
    var font: UIFont! // default is nil (system font 17 plain)
    var textColor: UIColor! // default is nil (text draws black)
    var shadowColor: UIColor! // default is nil (no shadow)
    var shadowOffset: CGSize // default is CGSizeMake(0, -1) -- a top shadow
....
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我定义一个这样的类,它也没有init函数.编译器会警告我.我怎么能像苹果那样做,隐藏实现,只声明接口.谢谢.

Thi*_*ilo 2

UILabel 未在 Swift 中实现。

您在这里看到的内容源自 UILabel 的 Objective-C 头文件。