__attribute__ ((deprecated)) does not work on objective-c protocol methods?

后端 未结 3 715
北海茫月
北海茫月 2021-02-05 18:33

I need to deprecate a single method in objective-c protocol. On normal class/instance methods I add __attribute__ ((deprecated)); after declaration.

It seem

3条回答
  •  独厮守ぢ
    2021-02-05 19:18

    Apple deprecated some methods in the UITableViewDelegate protocol, perhaps you'll be able to find the solution using Apple's code as example.

    The relevant code of the protocol is as follows:

    - (UITableViewCellAccessoryType)tableView:(UITableView *)tableView
             accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
     __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_2_0,__IPHONE_3_0);
    

    As you can see, Apple uses a macro. Perhaps this is the way to go?

    EDIT: As noted on the following link [1] __attribute__((deprecated)) is a GCC construct so this might not work in LLVM. I guess this is the reason Apple uses macros, so some other (or no) deprecation construct will be called when other compilers are used.

    [1] How to deprecate a method in Xcode

提交回复
热议问题