gpt4 book ai didi

ios - Swift AnyObject 到 Int 总是以 nil 结束

转载 作者:行者123 更新时间:2023-11-30 13:57:47 31 4
gpt4 key购买 nike

我正在尝试创建一个 AnyObject?成为和 Int 但它对我不起作用。我哪里出错了?

let user = ParseUser(json)
let user_id = user["user_id"] as? Int

print(user)
print(user_id)

这会打印

["user_id": 361, "gender": female, "email": ddd@gmail.com, "name": Bob]
nil

最佳答案

检查您的 ParseUser(json) 函数。这里的user_id不是Int。你可以查一下这本词典:

// Why gender, email and name field is not String?
// What type of them is that?
let user = ["user_id": 361, "gender": "female", "email": "ddd@gmail.com", "name": "Bob"]
let user_id = user["user_id"] as? Int

// Successfully printed "(Optional)361"
print(user_id)

关于ios - Swift AnyObject 到 Int 总是以 nil 结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33397716/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com