C언어의 경험이 전무한 Java 개발자가
objective-c 프로그램을 읽고 이해 및 분석을 할 수 있도록..
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"hello world");
[pool drain];
return 0;
}
obejctive-c는 The GCC Compiler를 통해서 컴파일하여야 한다.
window, linux에서 환경구성(https://www.tutorialspoint.com/objective_c/objective_c_environment_setup.htm)
Mac os에서 Xcode를 통한 helloworld 프로젝트 생성



objective-c 구성
기본적으로 아래와 같은 부분으로 구성된다.
#import <Foundation/Foundation.h> // Line 1
@interface SampleClass:NSObject // Line 2
- (void)sampleMethod; // Line 3
@end // Line 4
@implementation SampleClass // Line 5
- (void)sampleMethod { // Line 6
NSLog(@"Hello, World! \n"); // Line 7
}
@end
int main() { // Line 8
/* my first program in Objective-C */ // Line 9
SampleClass *sampleClass = [[SampleClass alloc]init];
[sampleClass sampleMethod]; // Line 10
return 0;
}

| 종류 | byte 단위 | 길이 |
|---|---|---|
| char | 1 | -128 ~ 127 or 0 ~255 |
| unsigned char | 1 | 0 ~ 255 |
| signed char | 1 | -128 ~ 127 |
| int | 2 or 4 | -32,768 ~ 32,767 or -2,147,483,648 ~ 2,147,483,647 |
| unsigned int | 2 or 4 | 0 ~ 65,535 ~ 0 ~ 4,294,967,295 |
| short | 2 | -32,768 ~ 32,767 |
| unsigned short | 2 | 0 ~ 65,535 |
| long | 4 | -2,147,483,648 ~ 2,147,483,647 |
| unsigned long | 4 | 0 ~ 4,294,967,295 |
| 종류 | byte 단위 | 길이 |
|---|---|---|
| float | 4 | 1.2E-38 ~ 3.4E+38 |
| double | 8 | 2.3E-308 ~ 1.7E+308 |
| long double | 10 | 3.4E-4932 ~ 1.1E+4932 |
int i, j, k;
char c, ch;
float f, s;
double d;
extern int d = 3, f = 5; // extern은 전역변수를 애기한다
int d = 3, f = 5;
byte z = 22;
char x = 'x';
#define
# import <Foundation/Foundation.h>
#define LENGTH 10
#define WIDTH 5
#define NEWLINE '\n'
int main() {
int area;
area = LENGTH * WIDTH;
NSLog(@"value of area : %d", area);
NSLog(@"%c", NEWLINE);
return 0;
}
const
#import <Foundation/Foundation.h>
int main() {
const int LENGTH = 10;
const int WIDTH = 5;
const char NEWLINE = '\n';
int area;
area = LENGTH * WIDTH;
NSLog(@"value of area : %d", area);
NSLog(@"%c", NEWLINE);
return 0;
}
둘다 동일한 결과

정의시
- (리턴타입) 메소드명:( 아규먼츠타입1 )아규먼츠명1
추가아규먼츠2:( 아규먼츠타입2 )아규먼츠명2 ...
{
함수 내용
}
선언 시
- (리턴타입) 함수명:( 아규먼츠타입1 )아규먼츠명1
추가아규먼츠2: ( 아규먼츠타입2 )아규먼츠명2... ;
++ C를 사용해본적이 없어서 익숙하지않다..ㅠㅠ
기본적인 연산자는 JAVA와 동일하여 제외하였음
뒤에 내용을 추가할 예정이다.
emd