2017-03-02 11 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、@" fileExt "' ' –

+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); 
関連する問題