【发布时间】:2021-11-10 22:01:58
【问题描述】:
这是我的代码:
override func style(node: Node) throws -> StyleNode {
guard let objectNode = try super.style(node: node) as? StyleNode
else {
throw UEErrors.unrecoverableError(message: "Could not create Node")
}
guard let stylesArray = node.stylesMap else {
throw UEErrors.unrecoverableError(message: "stylesMap is missing")
}
objectNode.stylesMap = stylesArray //error : Cannot assign value of type '[[StyleID : Style]]' (aka 'Array<Dictionary<String, Style>>') to type '[StyleID : Style]' (aka 'Dictionary<String, Style>')
return objectNode
}
注意:var stylesMap: [[StyleID: Style]]?
如何创建stylesArray 的字典? (我认为 javascript 中的 Map 是 swift 中的字典)
我正在尝试将 javascript 代码移植到 swift 中。下面是javascript代码:
static style(
node: Node,
baseProps: BaseConstructorProperties,
): this {
const stylesArray = assertNonNull(
Node?.stylesMap,
'stylesMap is missing',
);
return new this({
...baseProps,
stylesMap: new Map(stylesArray),
});
}
【问题讨论】:
-
您当前有一个
[StyleID : Style]数组,您正尝试将其设置为接受该类型的单个值的属性。大概,你需要决定你想要哪个项目。第一个? -
@jnpdx 是的第一个
标签: javascript swift dictionary