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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($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 11-12-2010, 09:25 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 10
toha is on a distinguished road
Default NSArray/NSDictionary into Mutable

Hi,

I want to hand-over a NSArray with NSDictionary entries to sub view controller to change data. I have to store in the dictionary additional key-value-pairs for editing (as current value and UITextField).

Is there a way to change a NSArray with NSDictionary into NSMutableArray and/or NSMutableDictionary to add key-value-pairs in the sub view controller?

Here is the code with creating the array/dictionary and the init of the sub view controller:
Code:
- (void) startEditPerson
{
    NSArray *anArray = [NSArray arrayWithObjects:
                            
                                [NSDictionary dictionaryWithObjectsAndKeys:
                                    @"Nickname", kEITitleKey,
                                    player.name, kEIValueKey,
                                    [NSNumber numberWithInteger: 
                                             kEditItem_Required], kEIRequiredKey,
                                    [NSNumber numberWithInteger: 
                                        EditItemTypeString], kEIEditingTypeKey,
                                 nil],
                             
                                [NSDictionary dictionaryWithObjectsAndKeys:
                                    @"Surname", kEITitleKey,
                                    person.surname, kEIValueKey,
                                    [NSNumber numberWithInteger: 
                                        kEditItem_Optional], kEIRequiredKey,
                                    [NSNumber numberWithInteger: 
                                       EditItemTypeString], kEIEditingTypeKey,
                                 nil],
                             
                                [NSDictionary dictionaryWithObjectsAndKeys:
                                    @"Address",kEITitleKey,
                                    person.address,kEIValueKey,
                                    [NSNumber numberWithInteger: 
                                          kEditItem_Optional], kEIRequiredKey,
                                    [NSNumber numberWithInteger: 
                                          EditItemTypeAddress], kEIEditingTypeKey,
                                 nil],

                                [NSDictionary dictionaryWithObjectsAndKeys:
                                    @"Phone",kEITitleKey,
                                    person.phone,kEIValueKey,
                                    [NSNumber numberWithInteger: 
                                                   kEditItem_Optional], kEIRequiredKey,
                                    [NSNumber numberWithInteger: 
                                        EditItemTypePhone], kEIEditingTypeKey,
                                 nil],
                             
                        nil];
                            
	EditItemsVC *editItemsVC = [[EditItemsVC alloc] initWithItems:anArray 
                                                                            target:self];
	
	
    [self.navigationController pushViewController:editItemsVC animated:YES];
	[editItemsVC release];
}
Thanks for help!

Torsten

Last edited by toha; 11-14-2010 at 04:46 AM.
toha is offline   Reply With Quote
Old 11-12-2010, 10:26 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

mutableCopy

Why not just start with mutable items?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 11-14-2010, 10:50 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 10
toha is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
mutableCopy
I'm not sure about mutableCopy. What I tried now is following code to convert a NSArray with NSDictionary items into NSMutableArray with NSMutableDictionary.

Code:
        NSMutableArray *mutArray=[[NSMutableArray alloc]init];
        NSUInteger uiItem=0;
        while (uiItem<[arrayEditItems count])
        {
            NSDictionary *dictItem=[arrayEditItems objectAtIndex:uiItem];
            NSMutableDictionary *mutDictItem=[[NSMutableDictionary alloc]initWithDictionary:dictItem];
            [mutArray addObject:mutDictItem];
            uiItem++;
        }
Quote:
Originally Posted by BrianSlick View Post
Why not just start with mutable items?
To start with MutableDictionary could be possible way. But why should a caller of a sub class know, that sub class need to add value-key-pairs in to array. That's why I need the convert.
toha is offline   Reply With Quote
Old 11-14-2010, 11:05 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

It doesn't really have anything to do with subclasses. You are making a design decision. If this data does not ever change, then non-mutable is fine. But you have already identified a need for the data to change. This suggests you should go mutable. You are trying to jump through several hoops here, when it would be considerably easier to simply start mutable.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 11-16-2010, 04:54 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 10
toha is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
It doesn't really have anything to do with subclasses. You are making a design decision. If this data does not ever change, then non-mutable is fine. But you have already identified a need for the data to change. This suggests you should go mutable. You are trying to jump through several hoops here, when it would be considerably easier to simply start mutable.
So I changed my code to use MutableDictionary and it works fine.

Thanks!
toha is offline   Reply With Quote
Reply

Bookmarks

Tags
nsarray, nsdictionary, nsmutuabledictionary

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: 370
7 members and 363 guests
apatsufas, Kirkout, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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