0

I used this answer to get a PHAsset URL, but it run async.

I tried to synchronize it using Semaphore, mutex and DispatchGroup, but no one worked.

I decide to change that answer to get URL synchronously, but I couldn't do it.

rick
  • 1,009
  • 2
  • 10
  • 28
  • 1
    Don't. Learn to understand asynchronous data processing. – vadian Aug 07 '18 at 08:00
  • You mean I should use callback? Couldn't do it without callback? – rick Aug 07 '18 at 08:04
  • Yes, use a callback. – vadian Aug 07 '18 at 08:05
  • So this lead me to call all function before this function using closure. I mean there will be a sequence of callbacks. Is it OK to call all functions in this hierarchy with callback? – rick Aug 07 '18 at 09:17
  • 1
    It depends on the design. For example if the asynchronous tasks are executed in a loop there is `DispatchGroup` to be notified when all tasks have finished. – vadian Aug 07 '18 at 09:20
  • Is it correct to call `DispatchGroup` `enter` before call `getURL` (Async func that give a closure as completion) and call `leave` in callback? I did it but it didn't work. – rick Aug 08 '18 at 05:26

0 Answers0