@fiy-fish
2015-07-15T20:04:11.000000Z
字数 809
阅读 1242
Objective-c
// main.m
// day04-02-description
//
// Created by Aaron on 15/7/6.
// Copyright (c) 2015年 Aaron. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Person.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *p = [[Person alloc] init];
NSLog(@"%p",p);
NSLog(@"%@",p);
NSLog(@"%@",[p description]);
//NSNumber 作为介质来将基本类型转为对象类型或者将对象类型转为基本类型
NSNumber *num1 = [NSNumber numberWithInt:10];
int num2 = [num1 intValue];
NSLog(@"num2--->%d",num2);
NSLog(@"%@",num1);
BOOL rec = [num1 boolValue];
NSLog(@"%d",rec);
}
return 0;
}
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
NSString *_name;
NSInteger _age;
}
@end
#import "Person.h"
@implementation Person
-(instancetype)init
{
if(self = [super init])
{
_name = @"蜡笔小新";
_age = 3;
}
return self;
}
-(NSString *)description
{
return [NSString stringWithFormat:@"%@的年龄是%ld",_name,_age];
}
@end