Swift 获取字符串长度

2018-01-27  本文已影响0人  Wougle

今天在看一个demo时,注意到在Swift3.2里获取字符串长度是这样写的:

let currentCharactorCount = (textView.text?.characters.count)!

而在Swift4.0中发现这样写会报错:
'characters' is deprecated: Please use String or Substring directly
原来在Swift4.0中用Count直接可以获取字符串长度

Swift4.0中获取字符串长度
let currentCharactorCount = textView.text!.count

这样就可以取到啦

上一篇 下一篇

猜你喜欢

热点阅读