Referencing an NSOperation object in its own completion block with ARC

前端 未结 3 1297
醉梦人生
醉梦人生 2021-02-05 18:46

I\'m having difficulty converting some NSOperation code to ARC. My operation object uses a completion block, which in turn contains a GCD block that updates the UI on the main t

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-05 18:54

    Accepted answer is correct. However there is no need to weakify operation as of iOS 8 / Mac OS 10.10:

    the quote from NSOperation documentation on @completionBlock:

    In iOS 8 and later and OS X v10.10 and later, this property is set to nil after the completion block begins executing.

    See also this tweet from Pete Steinberger.

提交回复
热议问题