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 > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-25-2009, 07:27 AM   #1 (permalink)
Eager to Learn Member
iPhone Dev SDK Supporter
 
mkenney's Avatar
 
Join Date: Sep 2009
Posts: 76
mkenney is on a distinguished road
Red face Newbie: Data Structure method similar to perl hashes?

I'm new to Objective-C and coming from perl. In perl I used hashes to store most of the things I would do as I had a lot of key value pairs. What is a good way to store this data in Objective-C to allow it to be easily updated as well as passed from object to object. I'll list a couple of sample data here as well since I'm probably not describing this well:

ThingA 4
ThingD 1
Widget 5
Name "JimJim"

In perl I would set this up as:
Code:
my %collection=(
'ThingA'=>4,
'ThingD'=>1,
'Widget'=>5,
'Name'=>"JimJim",
);
And call a variable like:
Code:
$collection{ThingA};
Is there something similar in Object-C or PLEASE feel free to tell me a better way, I know I don't do things as cleanly as they should be and would love to learn!!!

Mark
mkenney is offline   Reply With Quote
Old 09-25-2009, 11:24 AM   #2 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
FlyingDiver will become famous soon enough
Default

You want to use NSDictionary:

Code:
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: 
	@"4", @"ThingA",
        @"1", @"ThingD", 
        @"5", @"Widget", 
        @"JimJim", @"Name", 
        nil];

NSString *name = [dict objectForKey: @"Name"];
joe
FlyingDiver is offline   Reply With Quote
Old 09-30-2009, 08:26 AM   #3 (permalink)
Eager to Learn Member
iPhone Dev SDK Supporter
 
mkenney's Avatar
 
Join Date: Sep 2009
Posts: 76
mkenney is on a distinguished road
Default

Quote:
Originally Posted by FlyingDiver View Post
You want to use NSDictionary:

Code:
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: 
	@"4", @"ThingA",
        @"1", @"ThingD", 
        @"5", @"Widget", 
        @"JimJim", @"Name", 
        nil];

NSString *name = [dict objectForKey: @"Name"];
joe
Thanks for the info!!! Sorry for the late reply, I got hit hard by the flu
mkenney 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
» Online Users: 459
13 members and 446 guests
Domele, Duncan C, Feldspar, MacBook MH, Objective Zero, patapple, peterwilli, pipposanta, PixelInteractive, Punkjumper, SLIC, taylor202, Today's Posts
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,694
Threads: 94,137
Posts: 402,950
Top Poster: BrianSlick (7,990)
Welcome to our newest member, peterwilli
Powered by vBadvanced CMPS v3.1.0

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