gpt4 book ai didi

ios - Swift 4 对成员 'jsonObject(with:options:)' 的引用不明确

转载 作者:行者123 更新时间:2023-11-30 11:36:18 24 4
gpt4 key购买 nike

尝试设置执行网络请求并尝试序列化响应的单元测试。我当前收到错误:对成员“jsonObject(with:options:)”的引用不明确。很困惑为什么会发生这种情况,因为单元测试应该知道什么是 JSONSerialization。是?

func testAccessKeys() {
let expected = expectation(description: "Run the Access request")
sut.request(.Access, data: nil) { finished, response in
if response != nil && finished == true {
guard let json = try? JSONSerialization.jsonObject(with: response!, options: .mutableContainers) as! [String:Any] else { return XCTFail("Access request was not a dictionary")}
XCTAssertNotNil(json?["id"])
expected.fulfill()
} else {
XCTFail("Access response was nil")
}
}
waitForExpectations(timeout: 3) { error in
if let error = error {
XCTFail("Access request failure: \(error)")
}
}

}

最佳答案

确保响应的类型为DataInputStream

这些是此函数唯一接受的类型,如 documentation 中所示。

关于ios - Swift 4 对成员 'jsonObject(with:options:)' 的引用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49729953/

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