Despite reading the ARC documentation about 5 times, scanning the devforums and 
reading Mike Ash's post about ARC I'm totally failing to find the correct 
bridge cast for the following piece of code when converting to ARC. 


-(void)addView:(UIView *)view forElement:(id)element
{
        CFDictionarySetValue( viewToElementMap, view, element );
}

in this case viewToElementMap is a CFMutableDictionary with retain/retain 
syntax. The reason for not using an NSMutableDictionary of course is because 
UIViews aren't copyable. I use this kind of map all over the place in my code 
(and wish constantly that iOS had a retain/retain map)

the ARC pre-check rightly complains about both view and element in that 
statement. Now, as the CFDictionary is going to CFRetain on add and CFRelease 
on removal, I thought I just wanted to __bridge cast both of them. That works 
for element, but not for view, ie if I try this

-(void)addView:(UIView *)view forElement:(id)element
{
        CFDictionarySetValue( viewToElementMap, (__bridge id)view, (__bridge 
id)element );
}

gives me 

error: incompatible types casting 'UIView *__strong' to 'id' with a __bridge 
cast [4]

but is fine about the element cast. 

and no combination of casts I've yet tried has managed to fix that. I don't 
think I want either __bridge_transfer or __bridge_retained, the former is for 
passing things back to obj-c classes and the latter I believe effectively 
transfers ownership and would require an extra CFRelease() which isn't going to 
happen, I don't want to transfer ownership, the dictionary will take its own 
ownership. 

Can someone please explain what I need here and why? Also, why is 'view' being 
treated differently from 'element'? Even if I change 'view' to type 'id' I 
still get a similar error message when using (__bridge id) on 'view', but not 
on 'element'. I looked at the signature of CFDictionarySetValue() to see if 
there were any qualifiers on the parameters, but they are both const void*. 
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to