如何在Swift 2.0中获取String的长度?

Bar*_*zyk 20 string swift swift2

到目前为止它是:

let string = "my example string"
if count(string) >= 3 { ... }
Run Code Online (Sandbox Code Playgroud)

但现在我收到一个错误:

count不可用:访问count集合上的属性.类型String不符合协议CollectionType

Bar*_*zyk 59

哦,很简单:

string.characters.count

  • 你知道吗!!你在上午9:03发布了这个问题,你在9:04 AM的时候有了一个很棒的愿景.无论如何还是很欣赏! (2认同)