Leoshen's Blog

swift4踩坑记录

2018-10-06   Programming,

<!--markdown--> - 废弃characters

swift 3
var count = string.characters.count

error
'characters' is deprecated: Please use String or Substring directly

swift 4
count = string.count
  • 废弃addingPercentEscapes
your codeswift 3
var url = @"http://www.example.com?username=姓名"
url = url.addingPercentEscapes(using: String.Encoding.utf8)!
//升级xcode10之后就一直报错,谷歌了一个下午。。。特发此记录
error
'addingPercentEscapes(using:)' is unavailable: Use addingPercentEncoding(withAllowedCharacters:) instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.

swift 4
url = url.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!

持续更新哦
欢迎大家关注我的新作品:
小沈词库(微信小程序搜索即可)
https://www.xsdict.cn

提交

评论接口维护中,暂时无法使用...