swift - 无法使用“([[Notice]?])”类型的参数列表调用“解码”
问题描述
当我确认可解码协议时,如何快速从解码器解码列表
struct ActiveModuleRespones:Codable {
var Notice:[Notice]?
var Module:[Module]?
public init(from: Decoder) throws {
//decoding here
let container = try from.singleValueContainer()
self.Notice = try? container.decode([Notice].self)
}
}
收到此错误:
Cannot invoke 'decode' with an argument list of type '([[Notice]?])'
请帮忙 ,
解决方案
它与变量本身混淆。更改变量的名称以修复它。
struct ActiveModuleRespones: Codable {
var notice: [Notice]?
var module: [Module]?
public init(from: Decoder) throws {
//decoding here
let container = try from.singleValueContainer()
self.notice = try? container.decode([Notice].self)
}
}
在 Swift 中,所有类型都有UpperCamelCase名称,几乎所有其他类型都有lowerCamelCase名称。
最后,使用try?
会杀死所有异常,你永远不会知道出了什么问题,请尝试使用它:
self.notice = try container.decode([Notice]?.self)
推荐阅读
- postgresql - 在 PostgreSQL 12 中使用 where 子句的确切方法是什么?
- python - 如何将索引和值转换为具有可调用列名的正确数据框?蟒蛇熊猫
- java - 检查一个数组是否是另一个数组的子集 - 特殊情况
- excel - 如果在列表框中的 json 数据 vba 的工作表中找到相同字段名称的所有价格,则解析并让用户选择
- numpy - 错误:numpy.core._exceptions.UFuncTypeError:ufunc'absolute'不包含签名匹配类型dtype('
dtype('
***import numpy as np def get_scale_factor(img): epsilon = 1e-7 scale_log = np.log(np.abs(img) + epsilon)
- android - Flutter - 初始化失败时以编程方式关闭应用程序
- angular - primeNg p-listbox filterValue 中的验证
- javascript - 发出 POST 请求时,NodeJS Access Denied Wrong Token 403 Error
- java - 从 jar 生成的 exe 文件未在 Windows 中运行
- flutter - Flutter:如何让这部分代码可滚动?