• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: minor ARC casting question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: minor ARC casting question


  • Subject: Re: minor ARC casting question
  • From: Igor Mozolevsky <email@hidden>
  • Date: Sun, 30 Oct 2011 15:55:39 +0000

On 30 October 2011 15:15, Matt Neuburg <email@hidden> wrote:
> In ARC, this is legal:
>
>    self.view.layer.contents = (id)[[UIImage imageNamed:@"boat.gif"] CGImage];
>
> And this is legal:
>
>    id ref = (id)[[UIImage imageNamed:@"boat.gif"] CGImage];
>    self.view.layer.contents = ref;
>
> But this is not:
>
>    CGImageRef ref = [[UIImage imageNamed:@"boat.gif"] CGImage];
>    self.view.layer.contents = (id)ref; // compilation fails
>
> In the last case, I have to change id to __bridge id. My question is: What's the difference in the cases? In all situations I'm casting a CGImageRef to an id, so why does ARC permit this in the first cases but not in the last? Is it because UIImage's CGImage method is a method, and this fact somehow gives ARC further info? Thx - m.


The compiler knows how to handle CF objects returned from Cocoa
methods, but doesn't know how to handle stuff created by yourself. I
thought that was fairly obvious from and explicit in the Transitioning
Notes?


Cheers,

--
Igor ;-)
_______________________________________________

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

References: 
 >minor ARC casting question (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: minor ARC casting question
  • Next by Date: Re: minor ARC casting question
  • Previous by thread: Re: minor ARC casting question
  • Next by thread: Re: minor ARC casting question
  • Index(es):
    • Date
    • Thread