美文网首页
IOS中方法和函数的区别

IOS中方法和函数的区别

作者: success_flower | 来源:发表于2019-11-20 09:10 被阅读0次

区别

  • 函数:属于整个文件,可以直接调用
  • 方法:依赖于类,只能通过实例对象或者类调用
#import "TestViewController.h"

static void method_002(){
    NSLog(@"--- %s----", __func__);
}
extern void method_003(){
    NSLog(@"--- %s----", __func__);
}

@interface Math : NSObject
@end
@implementation Math
- (void)method_001{
    NSLog(@"--- %s----", __func__);
}
@end

@interface TestViewController ()
@end
@implementation TestViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    //方法调用
    Math *m = [Math new];
    [m method_001];
    //函数调用
    method_002();
    method_003();
}
@end

相关文章

网友评论

      本文标题:IOS中方法和函数的区别

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