Making a Class Unavailable in Objective-C – LLVM/Xcode Tips and Tricks

So you have written an Objective-C class and you would like to mark it as unavailable so that others won’t be able to instantiate it?

The solution is simple. In the header file of your class, place the following code:

__attribute__((unavailable("Your message to the developer goes here")))

So here is an example of a class header file that uses this LLVM extension:

#import <Foundation/Foundation.h>

__attribute__((unavailable(“This class is unavailable. Please use the YourClass class instead”)))

@interface MyClass : NSObject


Once a programmer attempts to use this class, they will see something similar to this in Xcode (Click to Enlarge the photo):

Unavailable Objective-C Class

Click to Enlarge


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s