Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Mar 3, 2008, 10:52 AM   #1
macrumors newbie
Join Date: Feb 2008
Beginner Question: NSArray, NSDictionary, Bindings & Objects of different 'types'.

Hi all,

I'm a beginner programmer with Cocoa, but I've programmed on Windows for a while. What I'd like to do is the following; I've created some simple classes, with each representing a 'profession' i.e.

1. Fireman - {name,age, salary| getName, getAge, getSalary etc...}
2. Policeman - {name, Rank, Dept}| getName, getRank, getDept etc...}

The classes contain different 'attributes' for each profession, and getter/setter methods for these attributes.

I'd like to have an array (or whatever is appropriate) of these objects, and use bindings to tie the array to the UI. The problem is that all these objects are not of the same type.

From what I've read, I think these are my choices:

1. Have an NSArray of NSDictionary, using the NSDictionaries to store the attributes instead of creating objects.

2. Create an NSDictionary and add these different objects. If this is an option, how would I determine the object type would I have to do something different for the bindings?

3. Have one 'controller'class, that would manage different arrays of objects i.e. One Array of Firemen, another array of Policemen etc

I can do this easily enough when all the objects are of the same type, but I'm not sure how to handle the different Object types.

Thanks for any information/thoughts you might have,


breandan is offline   0 Reply With Quote
Old Mar 3, 2008, 11:00 AM   #2
Moderator emeritus
kainjow's Avatar
Join Date: Jun 2000
Do you want to display both types of objects together in the same table view? If so, then you don't need dictionaries. Just put the objects into an NSArray, bind the array via NSArrayController to your table view.

You can use "name" for both since they both support it, but for any other attributes you'll probably want to use an NSValueTransformer. Look up the docs on that.

Also, not sure if you're doing this, but don't use "getName" for a getter. Use name and setName: if you're writing your own methods (or use @properties if you're in Leopard).
kainjow is offline   0 Reply With Quote
Old Mar 3, 2008, 11:28 AM   #3
Thread Starter
macrumors newbie
Join Date: Feb 2008

Thanks for the quick reply.

Actually, I was hoping not to use a tableview at all; What I was hoping to do is have a tabview with 1 tab for each profession(tabs not visible); with each tab having a set of controls that can be used to set the attributes.

What I'd like to do is; when I 'load' an entry, the appropriate tab gets shown, and the controls on that page get filles with the attributes from the object.

Is this clearer?

Thanks for the info on the getter/setter methods. I haven't been doing this, but I'll start to.


breandan is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Bindings question: default value Qaanol Mac Programming 4 Nov 20, 2013 12:15 PM
NSUserDefaults, Bindings, NSPopup Button Question mdeh Mac Programming 0 Aug 27, 2013 11:47 PM
NSDictionary and NSUserNotification Question DavidBlack Mac Programming 7 Aug 19, 2013 12:43 AM
Theoretical Question on NSDictionary / NSArray ArtOfWarfare iPhone/iPad Programming 5 Jul 13, 2013 12:05 PM

Forum Jump

All times are GMT -5. The time now is 04:35 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013,, LLC