How to declare an open interface, for example apple. Another way to hide the implementation

Same as the UILabel class:

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 .... } 

But if I define a class like this that also did not have an init function. The compiler will warn me. How can I do the same as Apple to hide the implementation, only declare the interface. Thanks.

+6
source share
3 answers

UILabel is not implemented in Swift.

What you see here is derived from the Objective-C header file for UILabel.

+2
source

You should study the protocols more carefully. You can declare your protocol as follows:

 protocol UIViewProtocol { var text: String { get } ... } 

and refer to it later in its class:

 class MyClass : UIViewProtocol { .... } 

Apple Link: iOS 8 Protocols

+1
source

Try changing the class name and try.

 class MyClass : 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 } 
0
source

Source: https://habr.com/ru/post/970432/


All Articles