본문 바로가기

PDA&Mobile

아이폰 앱 개발 팁(1) : Stanford Lecture #2

* 본 포스트는 Blog.MissFlash.com에서 작성한 것으로, 원문 저작자의 동의없이 마음대로 퍼가실 수 없습니다. 포스트의 내용이 마음에 드시면 링크를 이용해주시면 감사하겠습니다.

> Stanford Lecture #2

* 특정 포맷의 문자열 작성
NSString *aString = @"Cool";
NSString *myString = [NSString stringWithFormat:@"It's '%@'", aString];

* 문자열 수정
- (NSString *)stringByAppendingString:(NSString *)string;
- (NSString *)stringByAppendingFormat:(NSString *)string;
- (NSString *)stringByDeletingPathComponent;

NSString *myString = @"Hello";
NSString *fullString;
fullString = [myString stringByAppendingString:@" world!"]; // Hello world!

* 유용 NSString methods
- (BOOL)isEqualToString:(NSString *)string;
- (BOOL)hasPrefix:(NSString *)string;
- (int)intValue;
- (double)doubleValue;

* 유용 NSMutableString methods
+ (id)string;
- (void)appendString:(NSString *)string;
- (void)appendFormat:(NSString *)format, ...;

* 유용 NSArray methods
+ arrayWithObjects:(id)firstObj, ...;
- (unsigned)count;
- (id)objectAtIndex:(unsigned)index;
- (unsigned)indexOfObject:(id)object;

* 유용 NSMutableArray methods
+ (NSMutableArray *)array;
- (void)addObject:(id)object;
- (void)removeObject:(id)oject;
- (void)removeAllObjects;
- (void)insertObject:(id)object atIndex:(unsigned)index;

* 유용 NSDictionary methods
+ dictionaryWithObjectsAndKeys:(id)firstObject, ...;
- (unsigned)count;
- (id)objectForKey:(id)key;

* 유용 NSMutableDictionary methods
+ (NSMutableDictionary *)dictionary;
- (void)setObject:(id)object forKey:(id)key;
- (void)removeObjectForKey:(id)key;
- (void)removeAllObjects;

[colors setObject:@"Orange" forKey:@"HighlightColor"];

* 유용 NSSet methods : Unordered collection of objects
+ setWithObjects:(id)firstObj, ...;
- (unsigned)count;
- (BOOL)containsObject:(id)object;

* 유용 NSMutableSet methods
+ (NSMutableSet *)set;
- (void)addObject:(id)object;
- (void)removeObject:(id)object;
- (void)removeAllObjects;
- (void)intersectSet:(NSSet *)otherSet;
- (void)minusSet:(NSSet *)otherSet;

* 유용 NSNumber methods
+ (NSNumber *)numberWithInt:(int)value;
+ (NSNumber *)numberWithDouble:(double)value;
- (int)intValue;
- (double)doubleValue;

* Selectors 활용 예
SEL mySelector = @selector(name);
SEL anotherSelector = @selector(setName:);
SEL lastSelector = @selector(doStuff:withThing:andThing:); // 3개의 arguments