Swift 6での書き方
現在は文字列のcountプロパティを使うよ。
|
1 2 |
let str = "あいうeo" print(str.count) // 5 |
以下はSwift 2.2当時の記録
Swift2.0にしたら出たエラー。
Swift2.0で文字列の長さを出すには、書き方が変わってるよ。
出たエラー
count is unavailable: access the count property on the collection. Type String doesn’t conform to protocol CollectionType
Swift1.2まで
|
1 |
count(str) |
Swift2.0から
|
1 |
str.characters.count |
これでおk
