What property should I use for a Dispatch Queue after ARC?

前端 未结 5 622
情深已故
情深已故 2020-12-04 15:28

I maintain a dispatch queue as a property with my view controller. I create this queue once in my view controller\'s init method, and reuse a few times for some background t

5条回答
  •  不知归路
    2020-12-04 16:07

    Updated answer:

    In current OS X and iOS, Dispatch objects are now treated as Obj-C objects by ARC. They will be memory-managed the same way that Obj-C objects will, and you should use strong for your property.

    This is controlled by the OS_OBJECT_USE_OBJC macro, defined in . It's set to 1 by default when your deployment target is OS X 10.8 or higher, or iOS 6.0 or higher. If you're deploying to an older OS, then this is left at 0 and you should see my original answer below.


    Original answer:

    Dispatch objects (including queues) are not Obj-C objects, so the only possible choice is assign. The compiler will throw an error if you try to use strong or weak. ARC has no impact on GCD.

提交回复
热议问题