Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Swift equivalent of NS_UNAVAILABLE?

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?

like image 854
J2K Avatar asked Feb 08 '19 19:02

J2K


1 Answers

You can use @available by marking the function as @available(*, unavailable).

You can read up on it here under Declaration Attributes.

enter image description here

like image 130
CodeBender Avatar answered Nov 04 '22 23:11

CodeBender