2017-03-02 6 views
0

아래 코드를 사용하여 앱에서 nsdictionary를 만듭니다.사전이 제대로 작성되지 않았습니까?

NSDictionary *allImportDict = [[NSDictionary alloc] initWithObjectsAndKeys: 
          [NSNumber numberWithInt:containerId], @"containerId", 
           [NSNumber numberWithInt:docTypeId], @"docTypeId",filextension, @"fileExt",metaDataFiellds, @"metaDataFields",[NSNumber numberWithInt:tmpRepoId], @"repositoryId",[NSNumber numberWithInt:1], @"pagesCount", 
           tmpSessionID, @"sessionId", fileName, @"title",guid, @"tmpFileName",[NSNumber numberWithInt:tmpUserID], @"userId", 
          nil]; 

있지만 allImportDict의

인쇄 설명을 아래와 같이 사전을 만들 :

{ 
    containerId = 2; 
    docTypeId = 1; 
} 

이 키의 대부분이 누락 된 모든 키를 포함하지 않는 이유 나를 인도하세요?

+0

'filextension, @ "파일을 확인하십시오 .Ext" –

+0

무엇이 문제입니까? – iOSGuy

+1

'filextension'은'nil' 인 것처럼 보이고 그 다음에 사전 구조를 멈춘다. – Larme

답변

0

NSDictionary "fileExt"매개 변수에 "nil"값이 포함되어 있습니다 .Plz를 업데이트하고 확인하십시오.

0

값에 유효성 검사를 추가하고 NSDictionaryNSMutableDictionary으로 바꿨습니다. null 값이 있으면 코드가 손상 될 수 있습니다. 다음 코드를 붙여 넣기 만 복사하면됩니다.

NSMutableDictionary *allImportDict = [[NSMutableDictionary alloc] init]; 

    if(containerId) { 
     [allImportDict setObject:[NSNumber numberWithInt:containerId] forKey:@"containerId"]; 
    } 

    if(docTypeId) { 
     [allImportDict setObject:[NSNumber numberWithInt:docTypeId] forKey:@"docTypeId"]; 
    } 

    if([self canUseString:filextension]) { 
     [allImportDict setObject:filextension forKey:@"fileExt"]; 
    } 

    if([self canUseString:metaDataFiellds]) { 
     [allImportDict setObject:metaDataFiellds forKey:@"metaDataFiellds"]; 
    } 

    if(tmpRepoId) { 
     [allImportDict setObject:[NSNumber numberWithInt:tmpRepoId] forKey:@"tmpRepoId"]; 
    } 

    [allImportDict setObject:[NSNumber numberWithInt:1] forKey:@"pagesCount"]; 

    if([self canUseString:tmpSessionID]) { 
     [allImportDict setObject:tmpSessionID forKey:@"sessionId"]; 
    } 

    if([self canUseString:fileName]) { 
     [allImportDict setObject:fileName forKey:@"fileName"]; 
    } 

    if([self canUseString:guid]) { 
     [allImportDict setObject:guid forKey:@"guid"]; 
    } 

    if(tmpUserID) { 
     [allImportDict setObject:[NSNumber numberWithInt:tmpUserID] forKey:@"userId"]; 
    } 

    NSLog(@"allImportDict: %@", allImportDict); 
관련 문제