Objective--C语言字符串方法命名

1:在JAVA语言里,你肯定定义一个返回值是String的函数(方法),肯定不要加上指针*标示。但是Objective--C就需要。

2:代码

#import <Foundation/Foundation.h>


// returns No if the two integers have the same
//value ,YES otherwise
BOOL areIntsDifferent(int thing1,int thing2)
{
    if (thing1 == thing2){
        return (NO);
    } else {
        return (YES);
    }

}//areIntsDifferent


NSString *boolString(BOOL yesNo)
{
    if(yesNo == NO){
        return (@"NO");
    } else {
        return (@"YES");
    }

}// boolString

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...

        BOOL areTheyDifferent;
        
        areTheyDifferent = areIntsDifferent(5, 5);
        
        NSLog(@"are %d and %d different? %@",5,5,boolString(areTheyDifferent));
        
        areTheyDifferent = areIntsDifferent(23, 42);
        
        NSLog(@"are %d and %d different ? %@",23,42,boolString(areTheyDifferent));
    }
    return 0;
}

 

3:扩展

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

 在代码中%@是NSLog()的专用格式说明符,它支持将NSString的值插入到NSLog中。

你可能感兴趣的:(Objective--C语言字符串方法命名)