Why is Apple's documentation that getting a ManagedObjectContext from a UIApplicationDelegate bad?

Curious why ManagedObjectContexts should be passed to UIViewControllers when they are created, and not just grabbing them from UIApplicationDelegate?

The docs say this makes your applications tougher, but I see no nuances about when to use the template.

Thank!

+5
source share
4 answers

Imagine that I ask you to do some kind of task, for example, to paint a room. If I just say β€œgo paint the room”, you need to ask me a lot of questions, for example:

  • Which room?
  • Where is the paint?
  • Where are the brushes?
  • ?

, . , . - , , . , " ", : ", 348, , ". , , . , .

( ); , , , . , , .

+7

, dependency injection UIViewControllers , UIApplication, .

MVC:

  • Model

  • ( )

  • ( )

+3

.

, Core Data , , . - , . , ; Cource Student, . , Core Data, . :

@interface Cource (StudentAccess)
-(NSArray*)studentsStortedByName;
@end

. Core Data . , - ? , , . :

@interface Cource (CourceAccess)
+(Cource*)caurceByID:(NSString*)courceID;
+(NSArray*)allCources;
+(NSArray*)courcesHeldByTeacher:(Teacher*)teacher;
@end

. . , CourceViewController StudenViewController, Core Data , , :

 -(id)initWithManagedObjectContext:(NSManagedObjectContext*)moc
                           student:(Student*)student;

:

 -(id)initWithStudent:(Student*)student;

. . , , studentsSortedByName. / , / , , . , .

+2

Apple . , , , .

, , -, , . , . , / , /. .

, - . , , .

, , . , quate-singleton . , , , - .

+1
source

All Articles