美文网首页
Objective-C 高级技巧(迭代更新)

Objective-C 高级技巧(迭代更新)

作者: 践行者 | 来源:发表于2017-04-19 09:43 被阅读63次
  1. 重载

黑魔法: attribute((overloadable))
<pre>
@interface ViewController ()

@end

NSString * attribute((overloadable)) mytest(NSString *x) {return @"aa";}
NSString * attribute((overloadable)) mytest(NSNumber *x) {return @"bb";}
NSString * attribute((overloadable)) mytest(NSDictionary *x) {return @"cc";}
NSString * attribute((overloadable)) mytest(int x) { return @"int"; }
NSString * attribute((overloadable)) mytest(double x) { return @"double"; }
NSString * attribute((overloadable)) mytest(long x) { return @"long"; }

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@", mytest(133333333));
    }
    @end
    </pre>

相关文章

网友评论

      本文标题:Objective-C 高级技巧(迭代更新)

      本文链接:https://www.haomeiwen.com/subject/ileczttx.html