> On Mar 21, 2015, at 9:28 PM, Quincey Morris > <quinceymor...@rivergatesoftware.com> wrote: > > On Mar 21, 2015, at 18:55 , Charles Srstka <cocoa...@charlessoft.com > <mailto:cocoa...@charlessoft.com>> wrote: >> >> The implicit conversions between String and NSString were removed in Swift >> 1.2 > > I’m sorry, I muddied the waters by using an incorrect description of > “bridging” earlier. > > Bridging in Obj-C is something like NSString vs CFString. The types and their > APIs are formally distinct at compile time, even though the objects might be > interchangeable at run time. If you use the “wrong” API for your declared > type, you’ll get a compiler error, though the semantics of what you wrote > might be sensible in terms of run-time behavior. > > I think it’s the same thing in Swift: String and NSString are distinct types, > and although their APIs almost exactly coincide, they’re not identical. (We > found that UTF8String, for example, is in NSString but not String.) That > implies the possibility of compile-time errors for things that might > otherwise be meaningful in run-time terms. That’s what happened to Jens, I > think. > > However, I don’t think the level of run-time interoperability is exactly > specified by API contract. It may be that there’s a shared toll-free bridged > String/NSString object, or it may be that there are run-time conversions from > “real” String objects to “real” NSString objects under some circumstances. > It’s not obvious which of the two it is, though someone who knows more about > Swift’s run-time than I do may be able to answer that definitively.
I’m pretty sure that “real” Swift strings are different from NSStrings at runtime. It’s not like NSString/CFString; it has to do an actual conversion, and is not toll-free bridged. If you convert between String and NSString a lot, it’ll have performance implications (which is why bridging to NSString just to get -UTF8String isn’t really a good idea). Charles _______________________________________________ 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