objective c -- helloword

//
//  main.m
//  tt
//
//  Created by soonest on 12年6月10日.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

BOOL isDifferent(int a,int b){
    
    if(a == b){
        return (NO);
    }else{
        return (YES);
    }
}

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

int main (int argc, const char * argv[])
{
    NSLog(@"Hello, Vincent Learn Objective-c");
    //Array
    NSArray *myArray = [[NSArray alloc] initWithObjects:@"One",@"Two",@"Three",nil];
    
    for(int i=0;i<[myArray count];i++)
    {
        NSLog(@"myArray %d :%@",i,[myArray objectAtIndex:i]);
    }
    
    BOOL areTheyDifferent = isDifferent(3, 4);
    NSLog(@"are %d and %d different? %@",5,5,boolString(areTheyDifferent));
    
    //for()
    int count = 3;
    for(int i=0;i<count;i++){
        NSLog(@"%d\n",i);
    }
    
    
    const char *words[3] = {"I'm","Fine","THX"};
    for (int i=0; i<3; i++) {
        NSLog(@"%s is %d characters long",words[i],strlen(words[i]));
    }
    
    return 0;
}

[Switching to process 34680 thread 0x0]

2012-06-10 19:29:06.532 tt[34680:407] Hello, Vincent Learn Objective-c

2012-06-10 19:29:06.536 tt[34680:407] myArray 0 :One

2012-06-10 19:29:06.537 tt[34680:407] myArray 1 :Two

2012-06-10 19:29:06.538 tt[34680:407] myArray 2 :Three

2012-06-10 19:29:06.539 tt[34680:407] are 5 and 5 different? YES

2012-06-10 19:29:06.539 tt[34680:407] 0

2012-06-10 19:29:06.540 tt[34680:407] 1

2012-06-10 19:29:06.541 tt[34680:407] 2

2012-06-10 19:29:06.542 tt[34680:407] I'm is 3 characters long

2012-06-10 19:29:06.543 tt[34680:407] Fine is 4 characters long

2012-06-10 19:29:06.544 tt[34680:407] THX is 3 characters long

Program ended with exit code: 0


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章