Explicar el enfoque de "pasar la batuta" cuando se trata de un contexto de objeto administrado anidado

in an Apple document regarding nested context it is clearly stated:

Los contextos anidados hacen que sea más importante que nunca que adopte el enfoque de "pasar la batuta" para acceder a un contexto (pasando un contexto de un controlador de vista al siguiente) en lugar de recuperarlo directamente del delegado de la aplicación.

Having a Java background I am used to work with a "pass a copy of the reference" when dealing and passing object. So, could you please provide an explanation of why "pas the baton" approach is strongly recommended.

The link to the doc Notas de la versión de datos básicos para OS X v10.7 e iOS 5.0

preguntado el 28 de agosto de 12 a las 09:08

1 Respuestas

Having a Java background I am used to work with a "pass a copy of the reference" when dealing and passing object. So, could you please provide an explanation of why "pas the baton" approach is strongly recommended.

It means the same thing. Apple recommend you pass on a pointer to NSManagedObjectContext from view controller to the next in favor of having a singleton class own the pointer and all view controllers asking it from that class directly (unnecessary strong coupling).

Respondido 28 ago 12, 09:08

Thanks, it is not quite clear, for me it looks the same approach if the pointer is the same, and still I don't understand the "more important than ever", seems a mandatory statement. Also, by passing the context, the controllers are coupled to each other, or not ? - Leonardo

Well, yes, view controllers in direct sequence to one another are coupled to an extent, but there are real use cases when you might want to swap out the current context. It is easy to do if you pass it along, but how would you do it if the view controller always asks it from the app delegate? Nested contexts encourage you to use a temporary context for detail view controller for example. - svena

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.