我正在尝试将我的应用从8升级到Xcode 9.3.1并出现以下错误:
在“id< NSCopying>”类型的对象上找不到字典元素的预期方法
我的代码是:
// Normalize the blending mode to use for the key.
// *** Error on next three lines ***
id src = (options[CCBlendFuncSrcColor] ?: @(GL_ONE));
id dst = (options[CCBlendFuncDstColor] ?: @(GL_ZERO));
id equation = (options[CCBlendEquationColor] ?: @(GL_FUNC_ADD));
NSDictionary *normalized = @{
CCBlendFuncSrcColor: src,
CCBlendFuncDstColor: dst,
CCBlendEquationColor: equation,
// Assume they meant non-separate blending if they didn't fill in the keys.
// *** Error on next line ***
CCBlendFuncSrcAlpha: (options[CCBlendFuncSrcAlpha] ?: src),
CCBlendFuncDstAlpha: (options[CCBlendFuncDstAlpha] ?: dst),
CCBlendEquationAlpha: (options[CCBlendEquationAlpha] ?: equation),
};
有人能指出我正确的方向吗?我在代码中加粗了错误。
答案 0 :(得分:1)
编译器认为options
的类型为id<NSCopying>
,而不是NSDictionary *,这是使用dictionary [key]语法所必需的。您的代码段不包括声明的位置,这是错误的位置。
答案 1 :(得分:0)
您必须投射对象选项
// Normalize the blending mode to use for the key.
id src = (((NSDictionary *)options)[CCBlendFuncSrcColor] ?: @(GL_ONE));
id dst = (((NSDictionary *)options)[CCBlendFuncDstColor] ?: @(GL_ZERO));
id equation = (((NSDictionary *)options)[CCBlendEquationColor] ?: @(GL_FUNC_ADD));
NSDictionary *normalized = @{
CCBlendFuncSrcColor: src,
CCBlendFuncDstColor: dst,
CCBlendEquationColor: equation,
// Assume they meant non-separate blending if they didn't fill in the keys.
CCBlendFuncSrcAlpha: (((NSDictionary *)options)[CCBlendFuncSrcAlpha] ?: src),
CCBlendFuncDstAlpha: (((NSDictionary *)options)[CCBlendFuncDstAlpha] ?: dst),
CCBlendEquationAlpha: (((NSDictionary *)options)[CCBlendEquationAlpha] ?: equation),
};