Archives
« 2026/09 »
| 일 |
월 |
화 |
수 |
목 |
금 |
토 |
| |
|
1 |
2 |
3 |
4 |
5 |
| 6 |
7 |
8 |
9 |
10 |
11 |
12 |
| 13 |
14 |
15 |
16 |
17 |
18 |
19 |
| 20 |
21 |
22 |
23 |
24 |
25 |
26 |
| 27 |
28 |
29 |
30 |
|
|
|
|
iOS 2015. 8. 21. 00:25
@ 메서드에 여러 인수 넘겨주기 -(int) setDay:(int) d: setMonth:(int) m; [instance setDay:30 :setMonth: 08];
@ 인수이름 없는 메서드 -(int) set:(int) n: (int) d; [instance set:1 :3];
@ static 키워드 값이 유지되는 static 형태로 변수를 선언할 수 있다. 메서드 내부에 선언하면 메서드 내부에서만 사용하고, 외부에 선언하면 어디서든 접근할 수 있다. static int count = 0;
@self 키워드 현재 메서드의 수신자 객체를 호출. [self method];
iOS 2015. 7. 13. 10:51
http://reysion.tistory.com/19
안드로이드처럼 필터링을 지원해주진 않지만 매크로를 통해 원하는 출력값만을 확인할 수는 있는 것 같다.
iOS 2015. 7. 7. 22:39
데이터 형 |
상수 예 |
NSLog 포멧 문자 |
char |
'a', '\n' |
%c |
short int |
-- |
%hi, %hx, %ho |
unsigned short int |
-- |
%hu, %hx, %ho |
int |
12, -97, 0xFFE0, 0177 |
%i, %x, %o |
unsigned int |
12u, 100U, 0XFFu |
%u, %x, %o |
long int |
12L, -2001, 0xffffL |
%li, %lx, %lo |
unsigned long int |
12UL, 100ul, oxffeeUL |
%lu, %lx %lo |
Float |
12.34f, 3.1e-5f, 0x1.5p10, 0x1P-1 |
%f, %e, %g, %a |
Double |
12.34, 1.3e-5, 0x.1p3 |
%f, %e, %g, %a |
| long double | 12.34L, 3.1e-5l | %Lf, %Le, %Lg | | id | nil | %p |
iOS 2015. 6. 26. 00:31
. 캡슐화로 인해 클래스 메소드 내의 인스턴스 변수에 직접 접근이 불가하다. . 클래스 메소드를 인스턴스 변수명과 똑같이 만들어서 return 값을 전달하는 것은 일반적이다. (요게 좀 특이함) | @implementation Test { // 변수선언 int testNum; } -(void) setTestNum: (int) n { // setter method testNum = n; } -(int) testNum { // getter method return testNum; } | cs |
. 클래스 객체의 생성 | // alloc를 호출해 메모리 공간을 확보하고 init로 초기화 시켜야 객체를 생성할 수 있는데, Fraction *frac3 = [[Fraction alloc] init]; // new 메소드를 통해 두가지 메소드를 한번에 처리해 객체를 간단히 생성할 수 있다. Fraction *frac4 = [Fraction new]; | cs |
iOS 2015. 6. 25. 23:59
@interface .선언한 클래스의 부모 클래스를 알려줌 .메소드의 선언부 .프로퍼티 항목 나열 | @interface Fraction: NSObject -(void) print; -(void) setNumerator: (int) n; -(void) setDnominator: (int) d; @end | cs |
@implementation .interface에서 선언한 메소드를 구현 .구현 파일에 부모클래스를 적을지는 편한대로(대개 안적는다고) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | @implementation Fraciton: NSObject { int numeratior; int denominator; } -(void) print { NSLog(@"%i/%i", numerator, denominator); } -(void) setNumerator: (int) n { numerator = n; } -(void) setDenominator: (int) d { denominator = d; } @end | cs |
프로그램 - 앞서 선언한 메소드들을 직접 사용한다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | int main(int argc, const char * argv[]) { @autoreleasepool { int sum; sum = 37 + 52 - 19; NSLog(@"The answer is %i", sum); int answer, result; answer = 100; result = answer - 10; NSLog(@"The result is %i\n", result + 5); Fraction *frac1 = [[Fraction alloc] init]; Fraction *frac2 = [[Fraction alloc] init]; [frac1 setNumerator: 1]; [frac1 setDenominator: 3]; [frac2 setNumerator: 3]; [frac2 setDenominator: 7]; NSLog(@"First fraction is:"); [frac1 print]; NSLog(@"Second fraction is;"); [frac2 print]; } return 0; } | cs |
|