1

I have a 3 x iCloudKit methods, fetch the banana database, fetch the apple database; and update the stock database.

But I have no way of knowing how long it will take the apple database to before it returns and/or the banana database with their answers; I effectively call them both at the same time.

Now how do I manage the update of the stock database since I don't want to update it until I have the apple & banana counts?

user3069232
  • 8,587
  • 7
  • 46
  • 87

1 Answers1

2

Use a boolean and call the same function when both banana and apple database return.

This function should check the value of the boolean, perform the third request depending on its value, change its value.

GaétanZ
  • 4,870
  • 1
  • 23
  • 30
  • Thanks Poqi, although unsure how that helps me. You see the problem is if your using CloudKit NSQueryOperation for example, it returns as soon as you launch the query; sure you have a completion block, but imagine two processes apple & bananas you set what boolean where? – user3069232 Jun 29 '15 at 05:58
  • Sure, I'm talking about the completion blocks. The boolean should be store as a property in the object which sets the completion blocks. – GaétanZ Jun 29 '15 at 06:39
  • I don't know what's a NSQueryOperation. But if you're using NSOperation in your app, use dependency. That's even better. – GaétanZ Jun 29 '15 at 07:05
  • Poqi, do you have a code example you can share with me on dependencies and NSOperations specifically with iCloudKit. I can find tutorials on the former, but documentation on the later not so easily? – user3069232 Jun 29 '15 at 07:08
  • I haven't my computer. But I learn a lot about NSOperation with the tutorial http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues and the course of the WWDC 2015 named "Advanced NSOperations". The course specially talks about NSOperation used with iCloud. You can find the sample code of that course at https://developer.apple.com/sample-code/wwdc/2015/ and here the course https://developer.apple.com/videos/wwdc/2015/ – GaétanZ Jun 29 '15 at 07:27