I have recently started programming for the iOS Platform but now I need some help figuring out how to do ‘something’:
- For my application I fetch some JSON data and put this data as objects into an Array
- This Array is written to my own PLIST file (in the docs directory)
Now when the users starts a sync action I:
- Fetch the data from the PLIST
- Get the timestamp for a certain object in the Array that came from the PLIST
- Use timestamp in new JSON request (for the new data)
So far so good.
Now for my (current) problem -> After receiving the new data (JSON req) I wish to update the timestamp of this ‘certain’ object in the array (and write this to the Plist).
Using an NSPredicate I am able to find the right set of data within the main Array (stampArr).
NSString *documentsDir = [NSHomeDirectory()stringByAppendingPathComponent:@"Documents"];
NSString *plistPath = [documentsDir stringByAppendingPathComponent:@"stamps.plist"];
NSMutableArray *stampArr = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"eventid = 1"];
NSMutableArray *filteredStampArr = [stampArr filteredArrayUsingPredicate:filter];
But now, after I update the filteredStampArr, I want to update the main Array with the data from the filtered Array.
In other words, I need to update the object from the Array with the new ‘timestamp’ (field of object).
I could off course use something like [stampArr addObject: [filteredStampArr copy]] after changing the filterd array but that would just create a duplicate of the information. I wish to overwrite the original object.
Somehow (I think) I need a ‘pointer’ that tells me the location of the data in the original array so that I can change the data directly in the main array?
(I hope my questions is clear – If not please say so)
Get the item, find it’s index in
stampArrand replace it with thenewItem.