Re: cannot invoke 'substringToIndex' with an argument list of type '(Int)'
Re: cannot invoke 'substringToIndex' with an argument list of type '(Int)'
- Subject: Re: cannot invoke 'substringToIndex' with an argument list of type '(Int)'
- From: Charles Srstka <email@hidden>
- Date: Tue, 07 Jul 2015 02:53:35 -0500
On Jul 7, 2015, at 2:47 AM, Rick Mann <email@hidden> wrote:
>
>
>> On Jul 7, 2015, at 00:46 , Charles Srstka <email@hidden> wrote:
>>
>> You don’t have an NSString. You have a String. It works differently.
>
> Well, they're toll-free bridged, and substringToIndex() is a method on NSString (or so I thought). Anyway, it turns out to be an error in the documentation, so now I understand.
They are *not* toll-free bridged. When you cast one to the other, it actually does a conversion.
The documentation is not incorrect; the method on NSString *does* take an Int. If you try it on strings that are actually typed as NSString, you’ll see that they take an Int:
import Foundation
let str = "foobar" as NSString
let str2 = str.substringFromIndex(3)
This results in str2 being “bar”. Swift Strings, however, follow different rules, in order to be safe about cases where a character in a string takes up more than one UTF-16 code unit.
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