码迷,mamicode.com
首页 > 其他好文 > 详细

OC 方法声明使用

时间:2017-05-24 16:59:39      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:循环   turn   log   调用   方法   style   使用   self   nslog   

Person.h

#import <Foundation/Foundation.h>

@interface Person : NSObject {
    int _age;
}

- (void)setAge:(int)age; //法名是setAge:
- (int)age; // 方法名是age

// 方法名是setAge:andNo:
// - (void)setAge:(int)newAge andNo:(int)no;
@end

Person.m

#import "Person.h"

@implementation Person

- (void)setAge:(int)age {
    NSLog(@"调用了setAge方法:%i", age);
    _age = age;
    
    // 这是错误的写法,会导致死循环,无限调用set方法
    // self.age = newAge;// [self setAge:newAge];
}

- (int)age {
    NSLog(@"调用了age方法:%i", _age);
    
    return _age;
}
@end

 

OC 方法声明使用

标签:循环   turn   log   调用   方法   style   使用   self   nslog   

原文地址:http://www.cnblogs.com/liuwj/p/6899581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!