투케이2K

56. (Objective-C/objc) [간단 소스] NSDictionary 딕셔너리에 특정 key 키 값 포함 여부 확인 - allKeys 본문

Objective-C

56. (Objective-C/objc) [간단 소스] NSDictionary 딕셔너리에 특정 key 키 값 포함 여부 확인 - allKeys

투케이2K 2022. 9. 1. 16:06
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : OBJECTIVE-C

 

[소스 코드]

                  // -------------------------------------

                  // [http 요청 response 데이터를 딕셔너리로 받음]

                  NSDictionary *mast = [responseDict objectForKey:@"data"];
                  
                  // -------------------------------------

                  NSString *PRE_BUS_USED = [S_FinalData PRE_BUS_USED]; // MARK: [찾으려는 key 값]

                  if ([[mast allKeys] containsObject: PRE_BUS_USED] == true){
                      printf("\n");
                      printf("==================================== \n");
                      printf("[LoginViewController >> checkInfo() :: key 포함 확인] \n");
                      printf("==================================== \n");
                      printf("\n");
                      
                      // [key 있음] >> [프리퍼런스에 저장]
                      [[S_Preference shared] setStringWith_sKey:PRE_BUS_USED _sValue:[mast objectForKey: PRE_BUS_USED]];
                  }
                  else {
                      printf("\n");
                      printf("==================================== \n");
                      printf("[LoginViewController >> checkInfo() :: key 없음] \n");
                      printf("==================================== \n");
                      printf("\n");
                      
                      // [key 없음] >> [널 값 저장]
                      [[S_Preference shared] setStringWith_sKey:PRE_BUS_USED _sValue:@""];
                  }

                  // -------------------------------------

 

반응형
Comments