Need help setting up an Array Controller predicate

Custom Classes
ChildClass
childName – the child’s name
childCode – a unique ID
.

DayClass
	theChild --		     the childCode (from ChildClass) for the child
	arrivalTime --		 arrival time
	departureTime --	departure time
	.

Arrays
childrenArray – an array of ChildClass objects
daysArray – an array of DayClass objects

Array Controllers
childrenArrayController – creates ChildClass objects in childrenArray
daysArrayController – creates DayClass objects in daysArray

I have a single-column table that allows me to select a child’s name. This table is bound to the childrenArrayController.

I have a table that is bound to the daysArrayController. I want to show the arrival/departure times for the currently selected child from the single-column table above. I know I should be able to set this up using a predicate (and probably do it in IB) but I don’t know how to set this up.

Thanks in advance,
Brad Bumgarner

Model: Macbook (mid 2010)
AppleScript: xCode 3.2.6
Browser: Safari 7536.25
Operating System: Mac OS X (10.7)

Hi,

I would implement the daysArray object in the ChildClass.
Then you can display the dates just with bindings.
If you need a combined departure/arrival value in one table cell, use a read-only property to concatenate the strings in the getter

Stefan,

Thanks for your reply. I’m not sure how to set up the bindings. Here’s what I’ve done so far:

Custom Classes
ChildClass
childName – the child’s name
childCode – a unique ID
childDays – an array of DayClass objects <— added this property
.

DayClass
    theChild --             the childCode (from ChildClass) for the child <--- [b]deleted this property[/b]
    arrivalTime --         arrival time
    departureTime --    departure time
    .

Arrays
childrenArray – an array of ChildClass objects
daysArray – an array of DayClass objects <— deleted this array

Array Controllers
childrenArrayController – creates ChildClass objects in childrenArray
daysArrayController – creates DayClass objects in daysArray <— deleted this array controller

I created an init() method in ChildClass to initialize the array property (thanks to Fiz for his help).

on init()
	continue init()
	set childDays to current application's NSMutableArray's array()
	return me
end init

I’m not sure properly bind the arrival time and departure time columns in IB.

I figure I’m either getting close to getting this working --OR-- I’m making this much harder than it needs to be.:lol:

Bind the Content Array of daysArrayController to
childrenArrayController > Controller Key: selection > Model Key Path: childDays
Then bind the column(s) of the table view to
daysArrayController > Controller Key: arrangedObjects > Model Key Path: the appropriate property in the DayClass

Stefan,

Thanks so much for your help. I would not have come upon that on my own. I think I’ll actually be able to make some progress now!:smiley:

Thanks again,
Brad Bumgarner

p.s.: I really like bindings but I still haven’t completely got my head wrapped around them.

glad I could help

array controller bindings could be tricky, because unlike 1:1 bindings for e.g. buttons and text fields you need often one to many or even many to many relationships