 |
 |
|
 |
04-05-2009, 09:13 AM
|
#1 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 10
|
Data Merging
Hi guys,
I have an NSMutableArray that is populated from a plist file, and I have some other data that is dynamically generated in my application (distance data) for each object (dictionary) in my array. I am hoping to get some assistance in the best way to do this.
Basically I need to: - Pull data from Plist file into an array(done)
- Use location data from plist file to calculate distance (done)
- Combine the plist data with this new distance data into an array that I can then use for my display
My coding experience is in VB6 so I am little lost with the language here at times....
I have done a little searching but have not found what I need yet so would greatly appreciate some assistance or links through to some similar examples.
|
|
|
04-05-2009, 11:46 AM
|
#2 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 118
|
Hi,
I am pretty inexperienced as well so I may be missing the crux of the problem but can you not just use the "addObjectsFromArray:" method to add the generated values to the plist data Array:
Code:
[plistDataArray addObjectsFromArray:generatedArray];
or add both sets to a new array:
Code:
NSMutableArray *newArray = [NSMutableArray arrayWithArray:plistDataArray];
[newArray addObjectsFromArray:generatedArray];
Or a third option which I think might be what you are looking for, to interleave the values from each array:
Code:
NSMutableArray *newArray;
NSInteger counter = 0;
GeneratedObject *tempObject;
for(PlistObject *currentPlistObject in plistDataArray) {
[newArray addObject:currentPlistObject];
tempObject = [generatedArray objectAtIndex:counter];
[newArray addObject:tempObject];
counter++;
}
I have not tested any of this but hopefully you get the general idea and it is what you are looking for.
M.J.
|
|
|
04-06-2009, 07:55 AM
|
#3 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 10
|
Thanks for your help - the loop function in Objective-C was what I was really looking for. XCode Edit > Insert Text Macro set me going. This allowed me to manipulate the data for each object and then do a replaceobjectatindex.
|
|
|
04-06-2009, 12:04 PM
|
#4 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 118
|
Quote:
Originally Posted by BNZ
Thanks for your help - the loop function in Objective-C was what I was really looking for. XCode Edit > Insert Text Macro set me going. This allowed me to manipulate the data for each object and then do a replaceobjectatindex.
|
Cool, glad you got what you were looking for. Any chance that you could post the piece of code that you used so that I may learn something, I am not sure I fully understand. As I said, I am quite new to this as well.
Cheers.
M.J.
|
|
|
04-06-2009, 12:13 PM
|
#5 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 10
|
Of course
I have a basic if statement to see if the current location has been found, if it has it uses the same code as below with a bit more padding to calculate a distance, if current location has not been found the arrary of locations is updated with a new key called distance with a value of Location Not Found.
Basically it reads the object from the current array index into a dictionary (not required here as we allready know the location has not been found), uses the location information about the object that it pulled from the array (once again not shown here), creates a new string - distancestring, adds a new key to the array (distance) and adds the distancestring as the value to the new key.
Code:
for (i = 0; i < count; i++) {
//NSDictionary *itemAtIndex = (NSDictionary *)[tempArray objectAtIndex:i];
NSString *distanceString;
distanceString = @"Location Not Found";
NSArray *newObjectKeys = [itemAtIndex allKeys];
newObjectKeys = [newObjectKeys arrayByAddingObject:@"distance"];
NSArray *newObjectArray = [itemAtIndex allValues];
newObjectArray = [newObjectArray arrayByAddingObject:distanceString];
NSDictionary *newObjectDictionary = [NSDictionary dictionaryWithObjects:newObjectArray forKeys:newObjectKeys];
[tempArray replaceObjectAtIndex:i withObject:newObjectDictionary];
}
|
|
|
04-06-2009, 12:19 PM
|
#6 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 118
|
Thanks for posting that, it's clear now. Also I had never come across text macros before so it's good to know about that.
Cheers
M.J.
|
|
|
04-06-2009, 12:29 PM
|
#7 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 10
|
Quote:
Originally Posted by Dollopp
Thanks for posting that, it's clear now. Also I had never come across text macros before so it's good to know about that.
Cheers
M.J.
|
No, nor had I. If you type loop into the help search bar in xcode then hover your mouse over the results it expands this for you!
Great hidden feature for those of us new to xcode.
|
|
|
04-06-2009, 12:33 PM
|
#8 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 118
|
Quote:
Originally Posted by BNZ
No, nor had I. If you type loop into the help search bar in xcode then hover your mouse over the results it expands this for you!
Great hidden feature for those of us new to xcode.
|
The only thing is I am not sure what the difference between using that and autocomplete (if you know the name of the comand)?
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 508 |
| 54 members and 454 guests |
| alexcrick209, atsd, AXP, bbc z, BostonMerlin, brianmethod, cornishGeeza, dbarrett, dda, deden, DevJustin, Dorald, embedded, Gamer211, ggalante, gonk, harrytheshark, iPhoneDevelopment, IphoneSdk, Jeremy1026, jharrah, kjelleinar, krowczyk, Link, markbuchanan, MarkC, masc2279, mebarron, naomipunkclan, nibby, Noise, pbcbvba, pieter78, Sckah, Sesa, SimonK, sjdev, Snappy, soulless, StefanL, Tambourin, the1nz4ne, treazer, tturk, Type25, virvalid, Vivek Nirkhe, Vonswanko, wassupdoc, winklllll, x2on |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,507
Threads: 35,791
Posts: 156,790
Top Poster: smasher (2,449)
|
| Welcome to our newest member, soulless |
|