본문 바로가기

Objective-C

[Objective-C] Convert NSString to char * const char* cString = [nsStringObject cStringUsingEncoding:ASCIIEncoding]; OR NSString *foo = @"your text here"; const char *bar = [foo UTF8String]; 더보기
[Objective-C] Get html data from web - (NSString *) GetHtmlData:(char *)homepage{ NSError *error; NSURLResponse *response; NSData *dataReply; NSString *stringReply; NSString *getUrl = [NSString stringWithFormat:@"%s",homepage]; NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL: [NSURL URLWithString: getUrl]]; [request setHTTPMethod: @"PUT"]; [request setHTTPBody: [[NSString stringWithString:@"test"]dataUsingEncoding.. 더보기
[Objective-C] String Function in Object-C Unicode 문자열 조작 - (id) initWithUTF8String:(const char *)bytes 문자코드가 UTF8이고, 널 문자로 끝나는 형식의 C언어 문자열에서 정보를 복사한후 리시버를 초기화 합니다. - (const char *)UTF8String 문자 코드가 UTF-8이고, 널문자로 끝나는 형식의 C언어 문자열을 가리키는 포인터를 리턴합니다. 해제후에도 계속 사용할려면 복사 해두어야 한다. - (NSUInteger) length 문자열의 길리를 리턴 - (unichar)characterAtIndex:(NSUInteger)index 문자열내에서 index번째에 위치하는 문자를 리턴합니다. - (id) initWithCharacters:(const unichar *)characters l.. 더보기
[Objective-C] tokenizerWithString in ParseKit ParserKit을 이용하여 주어진 문자열을 토큰별로 분리 시키는 예제 먼저 문자열을 토큰별로 분리하여 그것에 대한 Type을 출력하는 예제이다. - (void) parserString{ NSString *s=@"2 !=sl/*한국어skd*/ bal @#WWW// comm"; PKTokenizer *t = [PKTokenizer tokenizerWithString:s]; PKToken *eof = [PKToken EOFToken]; PKToken *tok = nil; while(( tok = [t nextToken]) != eof){ NSLog(@"(%@) (%.f) : %@", tok.stringValue, tok.floatValue, [tok debugDescription]); } } 그래서 결과는 .. 더보기
[Objective-C] Memory 관리 Objective-C는 Reference Counting이라는 방법을 사용한다. 특정 객체를 사용할려면 Reference Counting값인 retain count를 증가 시키고, 패키 시킬때는 retain count를 감소 시킨다. retain count가 0이 되면 메모리로 부터 패기 된다. - alloc : 객체가 처음 생성될때 호출되며, retain count는 1이 된다. - copy : 새롭게 복사된 객체를 반환해 주며, retain count를 1로 만들어 준다. - retain : retain counter를 1만큼 늘려준다. 이미 생성된 객체에 대해서 소유권을 가지고 싶을때 retain 메서드를 이용한다. - release : 해당 객체의 retain counter를 1만큼 줄여준다. 해.. 더보기