不务正业之OC(二)点语法

大家不要和NSPredicate的点来指定路径搞混了,NSPredicate非常强大,基本把数据库的sql语法实现一遍,特别在遍历一个集合对象时,非常方便,一行代码搞定全部功能。
这边点语法指属性访问,所谓无码无真相,go

Person类实现:

#import "Person.h"
@implementation Person
@synthesize name;
@synthesize age;
 
- (NSString *) description{
    NSString *desc;
    desc = [[NSString alloc] initWithFormat:@"Person:name is %@,age is %ld", self.name,(long)self.age ];
    return desc;
}
@end

main方法:

#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[])
{
 
    @autoreleasepool {
        Person *person = [[Person alloc] init]; //这里为啥不[person release]?就因为自动释放噢
        person.name = @"liyi(my son)";
        person.age = 1;
        NSLog(@"%@",person);
    }
    return 0;
}

运行结果:

2014-04-27 16:06:06.526 Person[9841:303] Person:name is liyi(my son),age is 1
Program ended with exit code: 0

Post a Comment