ios – Swift 3’Any’类型的值没有会员’对象’

ios – Swift 3’Any’类型的值没有会员’对象’,第1张

概述我更新了 swift 3,发现了很多错误.这是其中之一: Value of type ‘Any?’ has no member ‘object’ 这是我的代码: jsonmanager.post( "http://myapi.com", parameters: nil, success: { (operatio 我更新了 swift 3,发现了很多错误.这是其中之一:

Value of type ‘Any?’ has no member ‘object’

这是我的代码:

Jsonmanager.post( "http://myAPI.com",parameters: nil,success: { (operation: AFhttpRequestoperation?,responSEObject: Any?) in                        if(((responSEObject? as AnyObject).object(forKey: "Meta") as AnyObject).object(forKey: "status")?.intValue == 200 && responSEObject?.object(forKey: "total_data")?.intValue > 0){                            let aa: Any? = (responSEObject? as AnyObject).object(forKey: "response")                            self.data = (aa as AnyObject).mutablecopy()                         }

新错误更新:

Optional chain has no effect,Expression already produces ‘Any?’

Cannot call value of non-function type ‘Any?!’

它在以前的版本7.3.1 swift 2中运行良好.

这是Json的回应:

{ "Meta":{"status":200,"msg":"OK"},"response":[""],"total_data":0}
解决方法 与Swift 2不同,Swift 3将Objective-C的ID导入为Any?而不是AnyObject? (见 this Swift进化提案).要修复错误,需要将所有变量强制转换为AnyObject.这可能类似于以下内容:
Jsonmanager.post("http://myAPI.com",parameters: nil) { (operation: AFhttpRequestoperation?,responSEObject: Any?) in    let response = responSEObject as AnyObject?    let Meta = response?.object(forKey: "Meta") as AnyObject?    let status = Meta?.object(forKey: "status") as AnyObject?    let totalData = response?.object(forKey: "total_data") as AnyObject?    if status?.intValue == 200 && totalData?.intValue != 0 {        let aa = response?.object(forKey: "response") as AnyObject?        self.data = aa?.mutablecopy()     }}
总结

以上是内存溢出为你收集整理的ios – Swift 3’Any’类型的值没有会员对象’全部内容,希望文章能够帮你解决ios – Swift 3’Any’类型的值没有会员’对象’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101811.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存