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: Charles Srstka <email@hidden>
- Date: Sat, 21 Mar 2015 20:55:40 -0500
> On Mar 21, 2015, at 6:41 PM, Jens Alfke <email@hidden> wrote:
>
>> On Mar 21, 2015, at 2:13 PM, Quincey Morris <email@hidden <mailto:email@hidden>> wrote:
>>
>> Well, “String” is not “NSString”.
>
> Sure, but it’s bridged with NSString. The “Using Swift With Cocoa” book says: “Swift automatically bridges between the String type and the NSString class. This means that anywhere you use an NSString object, you can use a Swift String type instead … you should almost never need to use the NSString class directly in your own code.”
The implicit conversions between String and NSString were removed in Swift 1.2, in order to make the type system “simpler and more predictable". The documentation you’re quoting is simply out of date.
> On Mar 21, 2015, at 6:58 PM, Quincey Morris <email@hidden> wrote:
>
> The difference is mundane: String happens to have a “cStringUsingEncoding” method, but not a “UTF8String” method. NSString happens to have both. I don’t know why — though I can’t imagine it’s merely been overlooked in a class as common as String — but that difference is the reason for the error message.
The thing that’s odd is that the native Swift String’s implementation of cStringUsingEncoding uses the Foundation NSStringEncoding constants instead of something that wouldn’t require importing Foundation.
Charles
_______________________________________________
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