Init已在Swift 3中重命名为init(描述)错误

这段代码Swift 2中工作正常:
guard let userData = responseData["UserProfile"] as? [String : AnyObject] else { return }

var userProfileFieldsDict = [String: String]()
if let profileUsername = userData["Username"] as? Nsstring {
  userProfileFieldsDict["username"] = String(profileUsername)
}
if let profileReputationpoints = userData["ReputationPoints"] as? NSNumber {
  userProfileFieldsDict["reputation"] = String(profileReputationpoints)
}

但是,在Swift 3中,它会在userProfileFieldsDict [“reputation”]上引发错误

init has been renamed to init(describing:)

我的问题是为什么它会触发该行而不是userProfileFieldsDict [“username”]赋值行,以及如何修复它?我假设它是因为我正在将一个NSNumber转换为String,但我无法理解为什么这很重要.

NSNumber一个非常通用的类.它可以是从bool到long甚至是char的任何东西.所以编译器真的不确定确切的数据类型,因此它无法调用正确的String构造函数.

而是使用String(describe :)构造函数,如下所示

userProfileFieldsDict["reputation"] = String(describing: profileReputationpoints)

关于它,这里有更多info.

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...