Objective-C语言调用方式
示例
调用实例方法:
[classInstance hello];
@interface Sample
-(void)hello; //公开类Instance方法
@end
@implementation Sample
-(void)hello{
NSLog(@"hello");
}
@end在当前实例上调用实例方法:
[self hello];
@implementation Sample
-(void)otherMethod{
[self hello];
}
-(void)hello{
NSLog(@"hello");
}
@end调用一个带有参数的方法:
[classInstance addInt:1 toInt:2];
@implementation Sample
-(void)add:(NSInteger)add to:(NSInteger)to
NSLog(@"sum = %d",(add+to));
}
@end调用类方法:
[Class hello];
@interface Sample
+(void)hello; //公开类方法
@end
@implementation Sample
+(void)hello{
NSLog(@"hello");
}
@end
热门推荐
10 红包祝福语简短10字
11 对银行的祝福语简短
12 病人祝福语老师寄语简短
13 结婚祝福语简短精彩短句
14 送同学的简短祝福语
15 烟酒店开业祝福语简短
16 新年祝福语姨姨简短
17 新年英文祝福语简短创意
18 感恩跨年祝福语大全简短