Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.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 08-13-2009, 11:53 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: Munich, Germany
Posts: 108
Default NSMutableArray to NSString

Hi,

anyone know how to convert a NSMutableArray to NSString?
What I want to do is, convert the NSMutableArray to a NSString and then store the string.
Im just having a problem with the converting.
Thanks alot!

(Later on I will of course have to convert the string back to the NSMutableArray!)
freshking is offline   Reply With Quote
Old 08-13-2009, 11:58 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,556
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

Code:
- (NSString *)componentsJoinedByString:(NSString *)separator
This assumes your array contains only NSString I believe.
smithdale87 is offline   Reply With Quote
Old 08-13-2009, 12:13 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: Munich, Germany
Posts: 108
Default

The array contains arrays, dictionarys and strings.
I would like to convert it all to a string, store it in the Keychain and be able to reverse the whole thing.
freshking is offline   Reply With Quote
Old 08-13-2009, 12:34 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,556
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

Well, do all the inner arrays and dictionaries contain strings?
smithdale87 is offline   Reply With Quote
Old 08-13-2009, 12:40 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: Munich, Germany
Posts: 108
Default

Yes. This is how they are arranged:

freshking is offline   Reply With Quote
Old 08-13-2009, 12:47 PM   #6 (permalink)
Digital Assertion
 
drewag's Avatar
 
Join Date: Aug 2009
Posts: 268
Default

Quote:
Originally Posted by freshking View Post
Yes. This is how they are arranged:

What is the purpose of converting it all to a string and then back? Are you trying to display it somewhere or are you just trying to save it?
__________________
Digital Assertion, LLC
Check out our iPhone apps:
Notecards: Great study tool for anytime anywhere!
Redirect: Addicting puzzle / action game!

Follow Digital Assertion on Twitter: DigAssertion

Follow me on Twitter: Andrew Wagner
drewag is offline   Reply With Quote
Old 08-13-2009, 12:50 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: Munich, Germany
Posts: 108
Default

Quote:
Originally Posted by drewag View Post
What is the purpose of converting it all to a string and then back? Are you trying to display it somewhere or are you just trying to save it?
Well, the user is able to add Dictionarys with strings attatched in any number he likes.
I want to add the whole 'data.plist' to the keychain. And for that I have to convert it all to strings first.
freshking is offline   Reply With Quote
Old 08-13-2009, 12:50 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,556
Send a message via ICQ to smithdale87 Send a message via AIM to smithdale87 Send a message via Skype™ to smithdale87
Default

Code:
NSMutableString* stringEncodedPlist = [[NSMutableString alloc] init];
for( NSDictionary* item in root )
{
     NSArray* contentAry = [item objectForKey:@"content"];
     NSString* name = [contentAry objectAtIndex: 1];
 
    NSDictionary* subItem = [contentAry objectAtIndex: 0 ];
    NSString* subText = [subItem objectForKey:@"Text"];
    NSString* subName = [subItem objectForKey: @"Name"];

   //here you want to combine all the elements
    NSString* result = [NSString stringWithFormat:@"****%@****%@****%@", subText, subName, name];

   [stringEncodedPlist appendString: [NSString stringWithFormat:@"%@^^^", result];
}


//do other stuff
[stringEncodedPlist release];
Now you should have a string where each "Item" in your plist is sepearted by '^^^'. Then within each "Item", the contents of the "Content" array, and the "Name" should all be separated by "***". I'm sure you can easily reverse this operation without me having to explain it.

By the way, I havent tested this, it's just a shot in the right direction, but theoretically it should work, although it may not be the best solution.
smithdale87 is offline   Reply With Quote
Old 08-13-2009, 01:46 PM   #9 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: Munich, Germany
Posts: 108
Default

That works perfectly!!! Thanks alot!

I don't want to bother you again but would it be possible to also give me the code to reverse that? Your code worked out so well that I would love to have it. Thanks alot again!
freshking is offline   Reply With Quote
Reply

Bookmarks

Tags
convert, nsmutablearray, nsstring, store

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
» Online Users: 253
16 members and 237 guests
2WeeksToGo, ADY, BrianSlick, dacapo, Dani77, Dattee, Duncan C, headkaze, jemicha, kapps11, mer10, mgon987, sneaky, timle8n1
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,743
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:41 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0