如何从api响应获取数据以快速显示在标签上
我正在尝试获取 API 数据以在标签中显示,我在模型中成功获取 api 响应,如何在视图控制器中获取响应值以显示在标签上。这是在 codeViewController 类中获取 json 响应的方法
private textCode:CodeModel
private func load() {
codeProvider.load(target: .myCode, withActivity: true) {[weak self] result in
switch result {
case .success(let response):
print(response,"response here")
self?.textCode = response
self?.output.perform(action: .didLoad)
case .failure(let error):
print(error)
}
}
}
extension CodeModel: codeViewControllerOutput {
var displayable: DisplayableCode {
DisplayableCode(user: textCode)
}
,我试图调用可显示的
private func fillFields() {
let d = model.displayable
codeLabl.text = d.someTextcode
}
致命错误:隐式解包时意外发现 nil 可选值
I am trying to get API data to display in label i get api response successfully in model, how i can get response values in viewcontroller to show on label. here is the method to get json response
private textCode:CodeModel
private func load() {
codeProvider.load(target: .myCode, withActivity: true) {[weak self] result in
switch result {
case .success(let response):
print(response,"response here")
self?.textCode = response
self?.output.perform(action: .didLoad)
case .failure(let error):
print(error)
}
}
}
extension CodeModel: codeViewControllerOutput {
var displayable: DisplayableCode {
DisplayableCode(user: textCode)
}
in codeViewController class i am trying to call displayable
private func fillFields() {
let d = model.displayable
codeLabl.text = d.someTextcode
}
Fatal error: Unexpectedly found nil while implicitly unwrapping an
Optional value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论