Can block capture of CoreFundation object?

In the Apple doc I can't seem to find what I can when I want to grab the CoreFoundation object .

But in Apple's Concurrency Programming Guide . The example code seems to use some code when the send object does not support ARC like so:

   void average_async(int *data, size_t len, dispatch_queue_t queue, void (^block)(int))

   {

        // Retain the queue provided by the user to make

        // sure it does not disappear before the completion

        // block can be called.

        dispatch_retain(queue);


        // Do the work on the default concurrent queue and then

        // call the user-provided block with the results.

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

           int avg = average(data, len);

           dispatch_async(queue, ^{ block(avg);});



           // Release the user-provided queue when done

           dispatch_release(queue);

       });
   }

      

Should I use it CFObject

as DispatchObject

before. But what if I need to call the block multiple times?

Maybe I can use it __attribute__((NSObject))

, but I don't know what will happen!

Does Apple say something about this?

+3


source to share


2 answers


I haven't seen anything on Apple explicitly, but I can see what is mentioned in the llvm.org documentation I found in detail on this cocoa -dev mailing list thread .



It looks like you should be fine when using it __attribute__((NSObject))

, since it gave an implicit " __strong

" qualification (from the documentation) and in a practical sense (from the mailing list stream), the object is retained when the block is queued and released when the block ends.

+1


source


First of all, dispatch_queue_t

not a Core Foundation object.



Dispatch objects are considered Objective-C objects by the compiler (for ARC and block targets) if the deployment target is iOS 6 + / OS X 10.8+ .

+1


source







All Articles