Reputation: 181
I am not able to create dictionary in objective c. I am getting warning as
Incompatible integer to pointer conversion sending nsinteger to parameter
Below is my code.
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);
I want to create a json like below:
{
"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
}
Upvotes: 0
Views: 115
Reputation: 21
NSDictionary accepts objects only, no basic types. You'll need to wrap your int inside an NSNumber
[NSNumber numberWithInt:tmpRepoId]
or, in modern Obj-C:
@(tmpRepoId)
and add this to the dictionary.
Generally, I'd like to recommend to use modern Obj-C for better readability, e.g.:
int containerId fmDic[@"ContainerId"].intValue;
NSDictionary *metaDataFiellds = @{ @"metaDataFields" : metaArray };
Also consider using NSInteger instead of int.
Upvotes: 1