loop through data source of table view

Trying to loop through all the data rows of a table who’s data is held in an NSArray Controller with data bindings.

Perviously in my ASS file I wrote

repeat with thestatusrow in (data rows of theData where "pending" is in contents of data cell filestatus) 
...
do some stuff
...
end repeat

In my ASOC file im writing it as

repeat with theWorkingRow in (my theData's valueForKey_("filestatus"))
where my theData's valueForKey_("filestatus") as string is "PENDING"
...
do some stuff
...
end repeat

sometimes it processes the first row and stops saying it can’t continue with the count - i’m obviously not getting it right and can’t find any examples elsewhere. Any Suggestions plz.

I’m not sure how you have it set up but the way I do it is to query the ArrayController.

--connect your array controller as an outlet to this
property ArrayController: missing value

--this gets the rows of the table whether sorted or not
set theArraysRows to theArrayController's arrangedObjects()

repeat with i from 1 to count of theArraysRows
	set theRowsValue to theArraysRows's objectAtIndex_(i - 1)'s valueForKey_("filestatus")
         if theRowsValue as string = "PENDING" then doSomething
end repeat

Rob

This is a good place to use the NSPredicate class. You would use Rob’s code to get the data:

--connect your array controller as an outlet to this
property ArrayController: missing value

--this gets the rows of the table whether sorted or not
set theArraysRows to theArrayController's arrangedObjects()


And then filter the resulting array something like this:

set aPredicate to current application's class "NSPredicate"'s predicateWithFormat_("filestatus = 'PENDING'")
set theList to theArraysRows's filteredArrayUsingPredicate_(aPredicate)

theList should now be a list of the matching records.

ok I have added the

property ArrayController: missing value

to the script, and have dragged from the App Delegate Outlet ArrayController to the Array Contoller object interface builder. (was that the right direction to drag)

Then added

set theArraysRows to theArrayController's arrangedObjects()

and then the repeat loop.

It giving an error *** -[testerAppDelegate toolbarStart:]: The variable theArrayController is not defined.

Have I dragged the connection wrongly in IB - im still a bit new to this binding and outlets stuff.

thanks again.

Are you sure you saved in IB after making the connection?

Yes just re done that to be sure.

So im right clicking on the App delegate and under outlets dragging the connection titled ArrayController onto the green Array Controller icon - Then saving.

Yes, you’ve made the connection the right way.

But I just realised there’s an error in Rob’s script that we both copied: the property is called ArrayController, but in the repeat loop we’ve used “theArrayController” – remove the “the” at the beginning.

Sorry about that - late night typing!

The NSPredicate is awesome. I saw that but overlooked the possibilities. Thanks Shane.

Rob

Thank you both - yes removing the ‘the’ did the job.