투케이2K

114. (Objective-C/objc) NSString compare 사용해 문자열로 선언된 정수 값 형태 데이터 비교 수행 실시 본문

Objective-C

114. (Objective-C/objc) NSString compare 사용해 문자열로 선언된 정수 값 형태 데이터 비교 수행 실시

투케이2K 2022. 10. 25. 10:25
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : OBJECTIVE-C

 

[소스 코드]

// MARK: - [헤더 파일에 정의 없이 : void 메소드 구현]
- (void)testMain {
    printf("\n");
    printf("==================================== \n");
    printf("[ViewController >> testMain() :: 테스트 메소드 수행] \n");
    printf("==================================== \n");
    printf("\n");
    
    
    /*
     ------------------------------------
     [요약 설명]
     ------------------------------------
     1. compare : NSString 문자열에 선언 된 정수값 형태 데이터를 비교할 때 사용합니다
     ------------------------------------
     */
    
    
    // [try catch 구문 정의 실시]
    @try {
        
        // [변수 선언]
        NSString *a = @"10";
        NSString *b = @"5";
        NSString *c = @"10";
        
        NSString *a_Compare_b = @"";
        NSString *a_Compare_c = @"";
        
        
        // [compare 사용해 주어진 숫자보다 크거나 같거나 작은지 여부 확인 실시]
        if ([a compare:b] == NSOrderedSame){
            a_Compare_b = @"정수값 동일";
        }
        else {
            a_Compare_b = @"정수값 다름";
        }
        
        if ([a compare:c] == NSOrderedSame){
            a_Compare_c = @"정수값 동일";
        }
        else {
            a_Compare_c = @"정수값 다름";
        }
        
        
        // [로그 출력 실시]
        printf("\n");
        printf("==================================== \n");
        printf("[ViewController >> testMain() :: 로그 결과 출력 실시] \n");
        printf("[a_Compare_b :: %s] \n", a_Compare_b.description.UTF8String);
        printf("[a_Compare_c :: %s] \n", a_Compare_c.description.UTF8String);
        printf("==================================== \n");
        printf("\n");

    }
    @catch (NSException *exception) {
        printf("\n");
        printf("==================================== \n");
        printf("[ViewController >> catch :: 예외 상황 확인] \n");
        printf("[name :: %s] \n", exception.name.description.UTF8String);
        printf("[reason :: %s] \n", exception.reason.description.UTF8String);
        printf("==================================== \n");
        printf("\n");
    }
}
 

[결과 출력]


반응형
Comments