Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not passing context to ViewControllers #1

Closed
organizr-zz opened this issue Dec 15, 2012 · 2 comments
Closed

Not passing context to ViewControllers #1

organizr-zz opened this issue Dec 15, 2012 · 2 comments

Comments

@organizr-zz
Copy link

Hello Adam,

I stumbled upon this helper class you made and while I like the idea, I noticed you don't follow Apple convention of passing the context from the Application Delegate to the subsequent view controllers.

Instead, you seem to load everything up every time you want to operate with core data. I don't know if this is is more correct but I wanted your opinion on why you made it this way.

What I mean is, loading a managed object model from disk in every view controller, just seems like you will make the app spend to much time loading the model when you can easily pass a pointer to the ManagedObjectContext instance to your controllers.

The only reason I can see for doing this is having more than one model, but maybe I am not seeing something.

Well, thank you in advance for your reply.

@adamgit
Copy link
Owner

adamgit commented Dec 15, 2012

Early versions of this class kept the stack in memory as a singleton, but I
found it made no appreciable difference in real apps, so I removed it for
simplicity. If you WANT TO pass the stack around, go ahead and do so,
there's nothing stopping you.

But please note: Apple's approach is wrong and very dangerous, since their
code is not thread-safe, in a "bad" way. It's best for each class to own
its own local stack of CD classes, and be guaranteed that no other thread
is messing with them.

This is how Apple designed CoreData to work!

On 15 December 2012 15:49, organizr notifications@github.com wrote:

Hello Adam,

I stumbled upon this helper class you made and while I like the idea, I
noticed you don't follow Apple convention of passing the context from the
Application Delegate to the subsequent view controllers.

Instead, you seem to load everything up every time you want to operate
with core data. I don't know if this is is more correct but I wanted your
opinion on why you made it this way.

What I mean is, loading a managed object model from disk in every view
controller, just seems like you will make the app spend to much time
loading the model when you can easily pass a pointer to the
ManagedObjectContext instance to your controllers.

The only reason I can see for doing this is having more than one model,
but maybe I am not seeing something.

Well, thank you in advance for your reply.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1.

@organizr-zz
Copy link
Author

Well, I just wanted to know the reasons for this decision, so that was helpful.

Thank you very much.

@adamgit adamgit closed this as completed Feb 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants