In Objective-C we can mark certain methods as NS_UNAVAILABLE meaning we will get a compiler level error if there is an attempt to call them. This can be useful when a sub class wants to reduce the scope of the api of the superclass it inherits from. For example a new UIView subclass might want to enforce that it has to be created via a nib and thus might mark initWithFrame as unavailable.
Swift has the @available marker but is there a simple way to mark a method is unavailable similar to NS_UNAVAILABLE in Objective-C?
You can use @available
by marking the function as @available(*, unavailable)
.
You can read up on it here under Declaration Attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With