Re: Why is NSString.UTF8String unavailable in Swift?
Re: Why is NSString.UTF8String unavailable in Swift?
- Subject: Re: Why is NSString.UTF8String unavailable in Swift?
- From: Quincey Morris <email@hidden>
- Date: Sun, 22 Mar 2015 03:59:07 +0000
On Mar 21, 2015, at 20:43 , Charles Srstka <email@hidden> wrote:
>
> 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).
What’s interesting about that is (assuming my playground test is correct) the native Swift String type only “acquires” cStringUsingEncoding when Cocoa is imported.
That means either:
a. The native class actually has that method, but doesn’t expose it to the world without “import Cocoa”, OR
b. The native class must implement some kind of selector forwarding that translates that method into a message to a real NSString conversion of the String instance, or some such roundabout thing.
Option (a) seems strange, but option (b) seems even stranger.
_______________________________________________
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