2017-02-24 13 views
0

대문자 c로 사전을 생성 할 수 없습니다. 나는 다음은 내 코드입니다객관적인 c에 사전을 생성 할 수 없습니까?

매개 변수 포인터 변환 전송 nsinteger에

호환되지 않는 정수로 경고를 받고 있습니다.

NSString *tmpSessionID = [[[AppSettings sharedAppSettings] getUserSession] objectForKey:@"UserSessionId"]; 
    int tmpRepoId = [[[[AppSettings sharedAppSettings] getUserRepository] objectForKey:@"RepositoryId" ]intValue]; 
    int tmpUserID = [[[[AppSettings sharedAppSettings] getUserSession] objectForKey:@"UserId"]intValue]; 
    NSDictionary * fmDic = [[AppSettings sharedAppSettings] getFolderModel]; 
    int containerId = containerId = [[fmDic objectForKey:@"ContainerId"]intValue]; 
    int docTypeId = selectedDcoumentType.docTypeId; 
    NSDictionary *metaData = [[NSDictionary alloc] initWithObjectsAndKeys: 
         selectFileIndices.columnId, @"ColumnId", 
         indexValue, @"Value", 
         nil]; 
    NSMutableArray *metaArray = [[NSMutableArray alloc]init]; 
    [metaArray addObject:metaData]; 
    NSDictionary *metaDataFiellds = [[NSDictionary alloc] initWithObjectsAndKeys: 
            metaArray, @"metaDataFields", 
            nil]; 

    NSDictionary *allImportDict = [[NSDictionary alloc] initWithObjectsAndKeys: 
          containerId, @"containerId", 
          docTypeId, @"docTypeId",selectFileIndices.transText, @"fileExt",metaDataFiellds, @"metaDataFields",tmpRepoId, @"repositoryId",1, @"pagesCount", 
           tmpSessionID, @"sessionId", @"1487918350642.jpg", @"title",guid, @"tmpFileName",tmpUserID, @"userId", 
          nil]; 
    NSLog(@"dictionary is %@",allImportDict); 

나는 다음과 같은 JSON을 만들려면 :

{ 
    "containerId": 2, 
    "docTypeId": 1, 
    "fileExt": ".jpg", 
    "metaDataFields": [ 
    { 
     "ColumnId": 1, 
     "Value": "23" 
    } 
    ], 
    "pagesCount": 1, 
    "repositoryId": 1, 
    "sessionId": "1587c3c9-f261-4749-ace4-c134d031ec38", 
    "title": "1487918350642.jpg", 
    "tmpFileName": "5f8a0340-bd65-476c-b377-67fa19121203", 
    "userId": 5 
} 
+1

오류가 발생한 행 – iOS

+4

NSDictionary는 스칼라 값 (예 : BOOL, NSInteger 등)을 저장할 수 없으며 개체 만 저장할 수 있습니다. NSNumber에 스칼라 값을 래핑하여 저장해야합니다. [NSNumber numberWithInteger containerId] – iOS

+0

요즘에는 Objective-C를 쓰는 사람이 아무도 없습니다. 사전 리터럴 또는 subscript 액세스에 대해 들었습니까? – deadbeef

답변

1

있는 NSDictionary 만 더 기본 유형을 객체을지지 않습니다. 당신은 현대의 Obj-C에서,

[NSNumber numberWithInt:tmpRepoId]

의 NSNumber

내부에 지능을 포장하거나해야합니다 :

@(tmpRepoId)

하고 사전에이를 추가 할 수 있습니다.

일반적으로, 나는

int containerId fmDic[@"ContainerId"].intValue; 
NSDictionary *metaDataFiellds = @{ @"metaDataFields" : metaArray }; 

가 대신 INT의 NSInteger를 사용하는 것이 좋습니다 : 더 나은 가독성을 위해 현대의 ​​Obj-C를 사용하는 예컨대을 추천하고 싶습니다.