开发者

iPhone CoreData fetch from delegate?

I've got a program which is working and uses Core Data for storage.

However, I'm not entirely sure if I should be keeping my fetch/update methods exclusively to the app delegate?

One example is for a questio开发者_开发知识库n within the app. The question has a "left" and a "right" statement.

The delegate currently creates the new QuestionVC and passes in the questionNumber for the question. Then the QuestionVC then does a fetch to get the question object and uses the left and right properties of the object to set the text on the screen.

Should I do this the other way round...

The delegate does a fetch on the question number and then creates the QuestionVC and passes in the question object. The QuestionVC then just has to get the left and right text without having to do a fetch at all.

Any tips, advice welcome.

Thanks

Oliver


Both approaches sound valid, but if you can design your view controller hierarchy in such a way that only one object needs to know about Core Data (i.e. pass the question object to your QuestionVC) then that's probably a simpler design, which is probably better.

I personally wouldn't be doing any fetching in my app delegate, though. My app delegates only set up Core Data (i.e. the managed object context) and pass that to the root view controller. I prefer to keep my app delegates as small as possible. I don't use them as an all-purpose singleton.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜