今天在看一个demo时,注意到在Swift3.2里获取字符串长度是这样写的:
let currentCharactorCount = (textView.text?.characters.count)!
而在Swift4.0中发现这样写会报错:
'characters' is deprecated: Please use String or Substring directly
原来在Swift4.0中用Count直接可以获取字符串长度
let currentCharactorCount = textView.text!.count
这样就可以取到啦