-1

I have created a NSManagedObjectContext with the ConcurrencyType NSPrivateQueueConcurrencyType. I read that we should use only perform Block API for every task with context.

My question is what will happen if do not use perform block API and directly execute task with context?

Saurav Nagpal
  • 1,247
  • 1
  • 10
  • 27

1 Answers1

2

Short: don't.

Longer: It depends on the internal implementation of the PrivateConcurrencyType version of NSManagedObjectContext. I presume, if you'll only use it from one thread and won't pass objects from that context to any other thread, it might work. Or not. But

  1. It's not guaranteed;
  2. If you're only going to use it from one thread, you need the Confinement concurrency type. Actually, I wouldn't probably use confinement at all just in case I'll need some concurrency later, but we're being theoretical here, right?
  3. Even if it works now, it might break in the future.

If you want to use this context from different threads, something will break for sure. Some data might disappear or reappear randomly (happened to me once), something might crash, and unicorns might take your office by storm. So just don't

FreeNickname
  • 7,398
  • 2
  • 30
  • 60
  • 1
    Confinement has been deprecated. As for the rest, OP should follow this advice. DO NOT use a private context without a performBlock. It will corrupt data eventually. – Marcus S. Zarra Apr 07 '16 at 15:39
  • @MarcusS.Zarra, thank you, I knew that it's not recommended, but I forgot that it's deprecated. I don't use it anyway :) – FreeNickname Apr 07 '16 at 18:08