开发者

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

开发者 https://www.devze.com 2022-12-09 15:29 出处:网络
My goal is to achieve compatibility across 3.x SDK versions for UIImagePickerController and it\'s allows(Image)Editing property.

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

精彩评论

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