J2K
J2K

Reputation: 1611

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?

Upvotes: 10

Views: 4738

Answers (1)

CodeBender
CodeBender

Reputation: 36660

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

Upvotes: 9

Related Questions