Re: CGImageRef as a property of a cocoa object
Re: CGImageRef as a property of a cocoa object
- Subject: Re: CGImageRef as a property of a cocoa object
- From: Roland King <email@hidden>
- Date: Sun, 15 Sep 2013 19:24:44 +0800
On 15 Sep, 2013, at 6:26 pm, Kevin Meaney <email@hidden> wrote:
> I'm using ARC on Xcode (unmentionable) on OS X redacted using latest features. I do believe however that we are allowed to discuss ARC related issues as they are already published on the clang.llvm.org website.
>
> Anyway I'd like to have the CGImageRef object treated the same as any cocoa object that is a property using the strong qualifier.
>
> I've seen the following discussed on stack overflow.
>
> @property (strong) __attribute__((NSObject)) CGImageRef snapShot;
>
> The discussion on stack overflow seems to suggest that using this attribute is not recommended and there is contradictory information. That you should use a typedef, or that you shouldn't.
>
> http://stackoverflow.com/questions/9684972/strong-property-with-attribute-nsobject-for-a-cf-type-doesnt-retain
>
> I'm not worried about the bug related to nonatomic that they are discussing, just the discussion about the use of the attribute.
>
> What is the recommended way of achieving what I'd like?
>
> Kevin
>
The clang document which bbum links to says it has to be a typedef. So that gives you two good reasons, one that the documentation mandates a typedef and the other that Bill Bumgarner weighed in. So I'd say, if you want to try this, you have to use a typedef.
The clang document also really recommends against using the typedef. Whereas the pointer will be treated correctly by ARC, it suggests other operations on it might not work, gives two examples, the inference I drew reading it was 'these two or other things we haven't really thought about'.
I don't know as there is a recommended way to do what you like. In the past when I have a CoreFoundation object I want as a property, I don't specify anything in the property definition apart from readwrite and I write my own getter and setter to CFRetain()/CFRelease() it (and remember to do something appropriate to release it in dealloc). Always worked fine for me at the expense of a few lines of code.
_______________________________________________
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