2009年2月4日 星期三

hello world example, NSLog, NSString

1. new project --> command line utility --> foundation tool

2. Hello.m
#import
int main (int argc, const char *argv[])
{
NSLog (@"Hello, Objective- C!");
return (0);
} // main

3. build and go
click build and go button or com+ R

4. show console
selelct Console from Run or cmd+shift+R


note:
1. import:
like include in C, but guarantees that a header file will be
included only once, no matter how many times the #import
directive is actually seen for
that file.

2. foundation framework:
handle features found in the layers beneath UI, such as
data structure and communication mechanisms
location:
/System/Library/Frameworks/Foundation.framework/Headers/

3. master header file
Each framework has a master header file that includes all the
framework’s individual header files. By using #import on the master header file,
you have access to all the framework’s features

4. NSLog
like printf, but also print date, time , and append newline
%@:
to print object, the object's description method defines what to print
ex:
- (NSString *) description 
    return (@"I am a hero"); 
}

5. NSString
begin with @, such as @"hello"
NSString's advantage:
(1) tell you length
(2)compare with another
(3)convert to interger or floating point

沒有留言:

張貼留言