Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mark property as deprecated in Objective C

Tags:

objective-c

How can I mark a @property in Objective C as deprecated?

like image 913
RobCroll Avatar asked Mar 19 '13 04:03

RobCroll


3 Answers

Unless you really want to deprecate based on iOS version, which I suspect you don't want to do, you can use DEPRECATED_ATTRIBUTE

@property (strong) NSObject *object DEPRECATED_ATTRIBUTE;
like image 70
Ben Trengrove Avatar answered Oct 17 '22 02:10

Ben Trengrove


from NSObjCRuntime.h

#define NS_AVAILABLE(_mac, _ios)
#define NS_AVAILABLE_MAC(_mac)
#define NS_AVAILABLE_IOS(_ios)
#define NS_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep)
#define NS_DEPRECATED_MAC(_macIntro, _macDep)
#define NS_DEPRECATED_IOS(_iosIntro, _iosDep)

you can use these macros

this is one example in UITableViewCell.h

@property(nonatomic,copy)   NSString *text NS_DEPRECATED_IOS(2_0, 3_0);                        // default is nil
like image 15
Bryan Chen Avatar answered Oct 17 '22 02:10

Bryan Chen


You can also use DEPRECATED_MSG_ATTRIBUTE("Use anotherProperty instead.") and provide a meaningful message hinting the user what to use in place of the deprecated property. Xcode will show a warning when the property is used.

example:

@property (nonatomic) NSString *someProperty DEPRECATED_MSG_ATTRIBUTE("Use anotherProperty instead.");

enter image description here

like image 8
akshay1188 Avatar answered Oct 17 '22 01:10

akshay1188