今天在看一個(gè)demo時(shí)馏锡,注意到在Swift3.2里獲取字符串長(zhǎng)度是這樣寫(xiě)的:
let currentCharactorCount = (textView.text?.characters.count)!
而在Swift4.0中發(fā)現(xiàn)這樣寫(xiě)會(huì)報(bào)錯(cuò):
'characters' is deprecated: Please use String or Substring directly
原來(lái)在Swift4.0中用Count直接可以獲取字符串長(zhǎng)度
Swift4.0中獲取字符串長(zhǎng)度
let currentCharactorCount = textView.text!.count
這樣就可以取到啦