美文网首页
Swift 获取字符串长度

Swift 获取字符串长度

作者: Wougle | 来源:发表于2018-01-27 22:27 被阅读0次

今天在看一个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

这样就可以取到啦

相关文章

网友评论

      本文标题:Swift 获取字符串长度

      本文链接:https://www.haomeiwen.com/subject/dsmoaxtx.html