투케이2K

59. (Objective-C/objc) NSLog 사용해 프로그램 로그 (log) 출력 - 배열 (array) , 딕셔너리 (dictionary) 한글 깨짐 해결 본문

Objective-C

59. (Objective-C/objc) NSLog 사용해 프로그램 로그 (log) 출력 - 배열 (array) , 딕셔너리 (dictionary) 한글 깨짐 해결

투케이2K 2022. 9. 6. 16:27
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : OBJECTIVE-C

 

[소스 코드]

// MARK: - [헤더 파일에 정의 없이 : void 메소드 구현]
- (void)testMain {
    printf("\n");
    printf("=============================== \n");
    printf("[ViewController >> testMain() :: 테스트 메소드 수행] \n");
    printf("=============================== \n");
    printf("\n");
    
    
    /*
     [요약 설명]
     1. NSLog : xcode 에서 로그를 출력 시 사용합니다
     2. NSLog 포맷 지정자 :
       
       %d : 10진수로 출력
       %o : 8진수로 출력
       %x : 16진수로 출력
       %f : 소수 출력
       %c : 문자를 출력
       %s : 문자열을 출력
       %@ : 오브젝트의 내용을 출력
     
     */
    
    
    // [초기 변수 선언 실시]
    NSString *strData = @"투케이";
    
    int intData = 10;
    
    double douData = 5.5;
    
    bool boolData = false;
    
    NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
    [mutableArray addObject:@"투케이"];
    [mutableArray addObject:@"hello"];
    [mutableArray addObject:@29];
    
    NSMutableDictionary *mutableDic = [[NSMutableDictionary alloc] init];
    [mutableDic setObject:@"투케이" forKey:@"name"];
    [mutableDic setObject:@"hello" forKey:@"insa"];
    [mutableDic setObject:@29 forKey:@"age"];
    
    
    // [NSLog 로그 출력 실시]
    NSLog(@"---------------------- \n");
    NSLog(@"[NSLog 로그 결과 확인 실시] \n");
    NSLog(@"---------------------- \n");
    NSLog(@"[strData [s] :: %s] \n", strData.description.UTF8String);
    NSLog(@"[strData [@] :: %@] \n", strData);
    NSLog(@"---------------------- \n");
    NSLog(@"[intData :: %d] \n", intData);
    NSLog(@"---------------------- \n");
    NSLog(@"[douData :: %f] \n", douData);
    NSLog(@"---------------------- \n");
    NSLog(@"[boolData :: %d] \n", boolData);
    NSLog(@"---------------------- \n");
    NSLog(@"[mutableArray [s] :: %s] \n", mutableArray.description.UTF8String);
    NSLog(@"[mutableArray [@] :: %@] \n", mutableArray);
    NSLog(@"[mutableArray [format] :: %@] \n", [NSString stringWithCString:[[mutableArray description] cStringUsingEncoding:NSASCIIStringEncoding] encoding:NSNonLossyASCIIStringEncoding]);
    NSLog(@"---------------------- \n");
    NSLog(@"[mutableDic [s] :: %s] \n", mutableDic.description.UTF8String);
    NSLog(@"[mutableDic [@] :: %@] \n", mutableDic);
    NSLog(@"[mutableDic [format] :: %@] \n", [NSString stringWithCString:[[mutableDic description] cStringUsingEncoding:NSASCIIStringEncoding] encoding:NSNonLossyASCIIStringEncoding]);
    NSLog(@"---------------------- \n");
}
 

[결과 출력]

 

 

반응형
Comments