Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone ($4.99)

dotnetIQ ($4.99)

Your First iPhone App ($1.99)

iPocket Tools 9 in 1 ($0.99)

Catch-Me (Free)

Alien Strike ($0.99)

Historic Olympic Medal-Table ($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-05-2009, 09:13 AM   #1 (permalink)
BNZ
New Member
 
Join Date: Apr 2009
Posts: 10
Default 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:
  1. Pull data from Plist file into an array(done)
  2. Use location data from plist file to calculate distance (done)
  3. 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.
BNZ is offline   Reply With Quote
Old 04-05-2009, 11:46 AM   #2 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 118
Default

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.
Dollopp is offline   Reply With Quote
Old 04-06-2009, 07:55 AM   #3 (permalink)
BNZ
New Member
 
Join Date: Apr 2009
Posts: 10
Default

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.
BNZ is offline   Reply With Quote
Old 04-06-2009, 12:04 PM   #4 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 118
Default

Quote:
Originally Posted by BNZ View Post
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.
Dollopp is offline   Reply With Quote
Old 04-06-2009, 12:13 PM   #5 (permalink)
BNZ
New Member
 
Join Date: Apr 2009
Posts: 10
Default

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];
}
BNZ is offline   Reply With Quote
Old 04-06-2009, 12:19 PM   #6 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 118
Default

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.
Dollopp is offline   Reply With Quote
Old 04-06-2009, 12:29 PM   #7 (permalink)
BNZ
New Member
 
Join Date: Apr 2009
Posts: 10
Default

Quote:
Originally Posted by Dollopp View Post
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.
BNZ is offline   Reply With Quote
Old 04-06-2009, 12:33 PM   #8 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 118
Default

Quote:
Originally Posted by BNZ View Post
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)?
Dollopp is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 21,507
Threads: 35,791
Posts: 156,790
Top Poster: smasher (2,449)
Welcome to our newest member, soulless
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:26 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0