The first one is a NSConstantString string. It's not like a malloc'd NSString. It's effectively a singleton. It doesn't mater how it's bridged because it can't be released. The second is a new NSURL that is allocated on the heap. It needs to be released so it needs to be bridged correctly to handle things properly.
Apple has made this more and more friendly since the WWDC beta of ARC over time with things like flags for constants from system headers and other basically constant things so don't have to bridge as much. Things like #pragma clang system_header and system_prefix in clang. Zac On Jul 27, 2013, at 11:31 AM, Matt Neuburg <m...@tidbits.com> wrote: > I feel like I've asked this before, but I don't feel I'm grasping the answer. > Why don't these work the same way under ARC: > > NSString* answer = @"42"; > int ans = CFStringGetIntValue((CFStringRef)answer); > > and > > NSURL* imageSource = [NSURL new]; > CGImageSourceRef src = > CGImageSourceCreateWithURL((CFURLRef)imageSource, nil); > > The first one compiles (with no explicit __bridge). The second one doesn't; > you must say __bridge explicitly. But why? They look completely parallel to > me. > > The mystery is compounded by the fact that if you omit the cast entirely in > the first example, the compiler claims that you need a bridged cast. But you > don't; you just need a cast. That feels like a bug; if a mere cast is > sufficient, the compiler should say so (and Fix-It should offer it as a > possible fix). > > m. > > -- > matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ > pantes anthropoi tou eidenai oregontai phusei > Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do > RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html > TidBITS, Mac news and reviews since 1990, http://www.tidbits.com > > > _______________________________________________ > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/zac%40zacbowling.com > > This email sent to z...@zacbowling.com
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com