数值型赋值给布尔型,1.NSString 包含着许许多多的特性,比如可以直接转化为数字类型(整型,浮点型)
1 NSString *test = @"this is my name";
3 NSLog(@"升值");
4 }
5 NSString *floatValueString = @"12";
6
7 NSLog(@"%d floatValue is%f ",[test length],[floatValueString floatValue]);
2.如何用NSLog输出BOOL类型的值。
NSLog(@"%@",isBool==YES? @"YES":@"NO");
3,可以讲整型赋值给BOOL类型,输出的结果为“
数值型赋值给布尔型,14”BOOL canAcceptDigital = 14;
NSLog(@"数值型赋值给布尔型,%d",canAcceptDigital);
4, 在objective-c中,YES代表1,而NO代表0
1 if (2) {
3 NSLog(@"YES is %d",YES);
4 NSLog(@"NO is %d",NO);
5 }
结果输出如下:
2011-12-27 21:12:04.763 lookbook[791:207] 2可以执行被执行
5.利用NSLog 中的%@,可以输出对象中的description函数中的定义。
头文件:person.h
2
3
4 @interface person : NSObject {
5
6 }
7 - (NSString *)description;
8 @end
实现文件person.m
#import "person.h"
@implementation person
- (NSString *)description
{
return @"my name is description";
}
@end
在 viewDidLoad中添加如下方法:
[super viewDidLoad];
person *d = [[person alloc]init ];
NSLog(@"person's description is %@",d);
}
运行之后,结果如下:
person's description is my name is description
下一章《面向对象编程基础知识》待续。 敬请期待!