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: Fritz Anderson <email@hidden>
- Date: Mon, 23 Mar 2015 08:34:26 -0500
> On 21 Mar 2015, at 11:10 PM, Jens Alfke <email@hidden> wrote:
>
>
>> On Mar 21, 2015, at 8:43 PM, Charles Srstka <email@hidden> wrote:
>>
>> 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).
>
> Then what would be the best way, given a String, to pass it to a C API that wants a char*?
>
> —Jens
À propos of Swift 1.1:
====
var str = "Hello, playground"
str.UTF8String // String does not implement
====
import Foundation // Let’s be minimal
var str = "Hello, playground"
str.UTF8String //String does not implement
====
import Foundation
var str = "Hello, playground"
(str as NSString).UTF8String
// Swift >= 1.1 does not implicitly convert String -> NSString.
// You have to force the conversion.
====
— F
_______________________________________________
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