In our application, when user register first time I need to save user key and its value. So first time I am created successfully like this format;
key: "ayi927GHt548"
data: {
userdata: [
{classId: "001", updateDate:"2018/02/12"}
]}
for this I get the class id and update date like this; here is the code
-(void)someMethod {
// ... do the process to get user class ID and user key
userClassID = @"001" // string declared global
userKey = @"ayi927GHt548" // string declared global
[apiManager saveUserInformationwithKey:userKey andValue:[self saveCurrentUserIformationIntoUserInfoAPI]];
}
-(NSDictionary *)saveCurrentUserInformationIntoUserInfoAPI {
NSDictionary *dictionaryUserInfo = @{
@"userData": @[
@{
@"classId": userClassID, // I get user class id
@"updateDate": [self getCurrentDateTime]
}
]
};
return dictionaryUserInfo;
}
// in global apimanager class i have a method to added on key value for get final solution
-(void)saveUserInformationwithKey:(NSString *)key andValue:(NSDictionary *)value {
NSDictionary *authInform = @{
@"key": key,
@"value": value
};
// call api for post method
}
this much I did correctly as what I want.
but the problem is for another case I need to append the new value to same existing 'userdata', without change the previous one, that is look like;
key: "ayi927GHt548"
data: {
userdata: [
{classId: "001", updateDate:"2019/02/18"},
{classId: "003", updateDate:"2019/02/21"} //? here this is the new object is which i want to add
]
}
how can I get like this? please help
currently Iam doing like this
NSMutableArray *dataFinal = [NSMutableArray arrayWithObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"data"]];
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:5] ;
[dict setObject:@"54455" forKey:@"classId"];
[dict setObject:[self getCurrentDateTime] forKey:@"updateDate"];
[dataFinal addObject:dict];
NSLog(@"Final: %@", dataFinal);
and the response look like this, but I need to append inside userdata
{
key = 12345;
data = {
userdata = (
{
updateDate = "2019/02/21";
classId = 0002;
}
);
};
},
{
updateDate = "2019/02/21";
classId = 54455;
}
userdata, please include that part also.