Master/Detail Design Question

19 views
Skip to first unread message

Todd Freese

unread,
Feb 27, 2014, 11:34:07 AM2/27/14
to mobile-c...@googlegroups.com
In my app I have a typical master/detail design. I have a masterViewController that handles the tableView and a detailViewController that handles the detail fields. When a row is selected, I get the model object and pass it to the detailViewController which then updates the GUI. This seems to work well.

However, I noticed in the ToDo example code, that rather than passing a model object to the detailViewController, it passes the doc id instead and the detailViewController retrieves the doc.

Is the method used by the sample code a better design? If so, why? Seems like an extra query.

Todd

Jens Alfke

unread,
Feb 27, 2014, 12:53:11 PM2/27/14
to mobile-c...@googlegroups.com

On Feb 27, 2014, at 8:34 AM, Todd Freese <to...@filmworkers.com> wrote:

However, I noticed in the ToDo example code, that rather than passing a model object to the detailViewController, it passes the doc id instead and the detailViewController retrieves the doc.
Is the method used by the sample code a better design? If so, why? Seems like an extra query.

I agree; IMO it’s better to pass the document. Probably even better to pass a model object.

(It’s probably not an extra query, though. CBLDatabase keeps an in-memory cache of CBLDocument objects, so -documentWithID: is a very cheap dictionary lookup if the CBLDocument with that ID is either already referenced elsewhere or has been used recently.)

—Jens
Reply all
Reply to author
Forward
0 new messages