Search code examples
iosswiftstring-length

length (byte-wise) of a string in swift 2.2


How do we find out the length (byte-wise) of a string [declared String type, not NSString] in Swift 2.2?

I know one way out is to use _bridgeToObejectiveC().length

Is there any other way out?


Solution

  • I think type casting is another easier way to use the methods, properties of NSString class.

    print((str as NSString).length)