swift - Xcode 问题?对象中的字典在变量检查器中将所有值显示为假,而值实际上是真的?
问题描述
class ViewController: UIViewController {
struct TestStruct: Decodable {
var dict: [String: Bool]?
}
override func viewDidLoad() {
super.viewDidLoad()
let json = """
{"dict":{
"test": true
}}
""".data(using: .utf8)!
let decoder = JSONDecoder()
let product = try? decoder.decode(TestStruct.self, from: json)
print(product)
}
}
使用这段代码,dict 字典的“test”值应该是 true。如果您在 print(product) 上放置断点(断点不在打印上,但我在屏幕截图中做了一个步骤),并查看左下角变量检查器中的变量值,
dict [字符串:布尔]?1 个键/值对 some [0] (key: String, value: Bool)
key String "test"
value Bool false
该值设置为假。
但是,当我们使用 po 访问该值时,该值似乎被正确设置为 true:
Optional<TestStruct>
▿ some : TestStruct
▿ dict : Optional<Dictionary<String, Bool>>
▿ some : 1 element
▿ 0 : 2 elements
- key : "test"
- value : true
我们想知道这里发生了什么?为什么 po 产品返回好的值,因为它包含字典,而 GUI 变量检查器说它设置为 false。
我们将 Xcode 10.1 用于测试项目。
解决方案
推荐阅读
- c - 在 C 程序中获取指针问题
- c++ - OpenCV fillPoly 与 floodFill 的差异
- c# - Azure 函数日志记录 - 双倍的日志条目?
- azure - Azure 规模集中 Windows VM 上的 Windows 自动更新
- python - MirroredStrategy:急切执行功能的输入不能是 Keras 符号张量
- c# - 分布式缓存会话在单独的请求中返回 NULL,为什么?
- android - Google Play 服务可以通过 APK 工作,但不能通过 Play 商店工作
- c# - Selenium Webdriver Specflow 测试的并行运行 - 静态访问器不能用于多线程执行
- android - 这是否违反了单一责任原则 (SRP)
- node.js - 当我想更新 mongodb 中的数据时 - 我得到 'invalid schema, expected mongodb'