开发者

Difference between "[context save:&error]" and "[appDelegate saveContext]"

开发者 https://www.devze.com 2023-03-09 11:44 出处:网络
I am currently writing an app that is using Core Data and reading up on i开发者_运维知识库t in Apple\'s documentation. I realize that when I created a window-based app in Xcode 4 it automatically adde

I am currently writing an app that is using Core Data and reading up on i开发者_运维知识库t in Apple's documentation. I realize that when I created a window-based app in Xcode 4 it automatically added an instance method:

-(void)saveContext;

But in the examples "around town" (most tutorials) I always see people using:

[context save:&error];

What are the different cases for using one over the other?


  • that isn't a class method, it is an instance method

  • [context save:&error] let's you check for an error and handle it explicitly

  • there better be an if() around that call to save: (i.e. don't just check error)

  • presumably, saveContext is intended to be a higher level operation that handles/presents the error internally. It probably calls save:.

0

精彩评论

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

关注公众号