How to deprecate a method in Xcode

前端 未结 5 2026
抹茶落季
抹茶落季 2020-12-07 12:08

We have our library we ship to our customers, and I\'d like to mark some methods as \"deprecated\" because we changed them (like Apple does in the iPhone SDK).

I\'ve

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 12:40

    You can also use more readable define DEPRECATED_ATTRIBUTE

    It defined in usr/include/AvailabilityMacros.h:

    #define DEPRECATED_ATTRIBUTE        __attribute__((deprecated))
    #define DEPRECATED_MSG_ATTRIBUTE(msg) __attribute((deprecated((msg))))
    

    Objective-C methods example:

    @interface MyClass : NSObject { ... }
    -(void)foo:(id)x DEPRECATED_ATTRIBUTE;
    
    // If you want to specify deprecated message:
    -(void)bar:(id)x DEPRECATED_MSG_ATTRIBUTE("Use baz: method instead.");
    ...
    @end
    

    You can also mark the whole class as deprecated:

    DEPRECATED_ATTRIBUTE
    @interface DeprecatedClass : NSObject { ... }
    ...
    @end
    

提交回复
热议问题