Re: Best Way to Hold Array of CFRefType’s
Re: Best Way to Hold Array of CFRefType’s
- Subject: Re: Best Way to Hold Array of CFRefType’s
- From: Clark Cox <email@hidden>
- Date: Mon, 18 Jan 2016 07:18:15 -0800
As long as you release them properly, you can just use NSAray/NSMutableArray:
[array addObject: CFBridgingRelease(cfObject)];
After the CFBridgingRelease, the CF-retain count is decremented, and NSArray becomes responsible for its lifetime. (this also means that there is no need to release the cfObject in your dealloc; that will be handled automatically when the array itself is deallocated (or when the cfObject is removed from the array)
When you want to get the object in the array, you can just use a __bridge cast:
CFTypeRef cfObject = (__bridge CFTypeRef)[array objectAtIndex: foo]l
This doesn’t affect the object’s retain count, so it is equivalent to a Get*() function in CoreFoundation. If you want the equivalent of a Copy*() function, you can use:
CFTypeRef cfObject = CFBridgingRetain([array objectAtIndex: foo]);
See <https://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html> for more information.
--
Clark Smith Cox III
email@hidden
> On Jan 18, 2016, at 05:44, Dave <email@hidden> wrote:
>
> Hi,
>
> I have need to keep an Array of CFRefType’s stored in an Object. What is the best way to do this? I can’t use malloc to create a C Array buffer to store them because I don’t know how many there will be to until after I have received them and there are likely to be a lot of them so don’t want to allocate a big buffer unless its needed. The Refs are created using CFCopy so are retained, I release them in the Objects dealloc method.
>
> I was thinking of using NSPointerArray but I’m not sure if this is appropriate for CFRefTypes?
>
> Any suggestions greatly appreciated.
>
> All the Best
> Dave
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden