iphone开发学习-Object - C 02

//小技巧 windows键+左键能够移动到行的最左边 

// windows + shift + 左键 向左选中整行

// 其它的上下和右键技巧类似

// 另外,windows键+V键用来粘贴,windows + C 用来复制, windows + X用来剪切,windows A全选

// 我们使用windows + shift + R 来打开console并运行程序

//Command line Utility 表示的是命令行程序

//Foundation Tool表示使用Foundation基础库

#import <Foundation/Foundation.h>

//====================================================

// return NO if the two integers have the smae valuse. YES otherwise

//====================================================

BOOL areIntsDifferent ( int p_intA, int p_intB )

{

 if ( p_intA == p_intB )

 {

 return (NO);

 }

 else 

 {

 return (YES);

 }

 

}

//====================================================

// given a YES value, return the human-readable string "YES". OtherWise return "NO"

//====================================================

NSString *boolString(BOOL p_yesNo )

{

 if (p_yesNo == NO )

 {

 return (@"NO");

 }

 else 

 {

 return (@"YES");

}

}

//====================================================

// main function

//====================================================

int main (int argc, const char * argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

 

    // insert code here...

BOOL areTheyDifferent = NO;

areTheyDifferent = areIntsDifferent( 10, 10 );

NSLog(@"are %d and %d different? %@", 10, 10, boolString(areTheyDifferent));

 

areTheyDifferent = areIntsDifferent( 20, 15 );

NSLog(@"are %d and %d different? %@", 20, 15, boolString(areTheyDifferent));

    [pool drain];

    return 0;

}

 

/*

 boolString()的返回类型是一个指向NSString的指针。

 @在这里表示接受一个NSString的指针作为参数打印。

 实际上,如果你使用了%@,实际上它表示接受任何对象,然后调用该对象的description方法输出信息。

 */


posted @ 2010-09-02 15:01  青龙  阅读(394)  评论(0编辑  收藏  举报