What is the Cocoa Touch equivalent to NSArrayController?
Asked Answered
C

3

6

Been starting to work with Core Data a bit, and while I've figured out how to use it in regular Cocoa applications, it seems it works a bit differently in Cocoa Touch. How do you bind entities to objects such as table cells in Cocoa Touch?

Concinnous answered 28/11, 2009 at 1:26 Comment(0)
P
4

If you're using CoreData on iPhone OS 3.0 and above, you'll want to look at NSFetchedResultsController. While not really an analog to NSArrayController, it is designed specifically to be used with UITableView and its controller.

It provides a way to load elements from persistence as needed, keeping in mind performance and memory constraints of the device. It's not as clean as simply binding things, but it will probably do everything you need (and more!) with a small amount of code.

Premedical answered 28/11, 2009 at 1:56 Comment(3)
Not seeing NSFetchedResultsController, though I do see a UITableViewController; are they analogous? In any case, I'm having trouble figuring out how to feed the array data to the controller. Thanks for the pointer about some of the environmental differences!Concinnous
NSFetchedResultsController may be found here: developer.apple.com/iphone/library/documentation/CoreData/…Premedical
NSFetchedResultsController basically works as a helper class to UITableView and UITableViewController. It is a model class which works with your CoreData objects, and prepares them for display in a table.Premedical
R
6

Unfortunately, bindings are not supported in the iPhone OS. See this page in the Apple developer docs.

I believe this means that you can't use the NSArrayController in the iPhone OS.

Redfish answered 28/11, 2009 at 1:44 Comment(1)
you mean fortunately. ArrayControllers are awful and confuse to set up.Player
P
4

If you're using CoreData on iPhone OS 3.0 and above, you'll want to look at NSFetchedResultsController. While not really an analog to NSArrayController, it is designed specifically to be used with UITableView and its controller.

It provides a way to load elements from persistence as needed, keeping in mind performance and memory constraints of the device. It's not as clean as simply binding things, but it will probably do everything you need (and more!) with a small amount of code.

Premedical answered 28/11, 2009 at 1:56 Comment(3)
Not seeing NSFetchedResultsController, though I do see a UITableViewController; are they analogous? In any case, I'm having trouble figuring out how to feed the array data to the controller. Thanks for the pointer about some of the environmental differences!Concinnous
NSFetchedResultsController may be found here: developer.apple.com/iphone/library/documentation/CoreData/…Premedical
NSFetchedResultsController basically works as a helper class to UITableView and UITableViewController. It is a model class which works with your CoreData objects, and prepares them for display in a table.Premedical
M
1

Jergason is correct: you can not use bindings or the NSArrayController with Core Data on the iPhone.

Instead, check out NSFetchedResultsController which "is intended to efficiently manage the results returned from a Core Data fetch request to provide data for a UITableView object."

Menton answered 28/11, 2009 at 1:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.