一致在忙着学OC,现在可有一些时间给大家分享一些,就分享给大家!
新建一个Text的类
#import <Foundation/Foundation.h>
@interface Test : NSObject@property(nonatomic,strong)NSString * name;
@property(nonatomic,strong)NSString * age;
@end
问题主要解决是在实现方法上写一个description方法
#import "Test.h"
@implementation Test
-(NSString *)description{
return [NSString stringWithFormat:@"%@ %@",_age,_name];
}
@end
#import <Foundation/Foundation.h>
#import "Test.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Test *test = [[Test alloc] init];
test.age = @"23";
test.name = @"木子李";
NSLog(@"%@",test);
}
return 0;
}
然后输出
2015-11-13 17:24:05.987 Xcode5[4834:71962] 23 木子李