开发者

How do I work around deprecated properties/methods with (possibly non-object) arguments?

My goal is to achieve compatibility across 3.x SDK versions for UIImagePickerController and it's allows(Image)Editing property.

// SDK 2.0 to 3.0
myImagePickerController.allowsImageEditing = YES;

// SDK 3.1
myImagePickerController.allowsEditing = YES;

Some research reveals some objective-c approaches, but what is considered best practice for handling deprecated methods?

  1. performSelector or NSInvocation for non-object arguments

  2. #define approach

  3. Any other recommended strategies...开发者_运维百科


NSString * key = @"allowsEditing";
if ([myImagePickerController respondsToSelector:@selector(setAllowsImageEditing:)]) {
  key = @"allowsImageEditing";
}
[myImagePickerController setValue:[NSNumber numberWithBool:YES] forKey:key];


wrap them in a @try @catch block to ensure a working feature regardless of a deprecated method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜