0

I am trying to upgrade my app to Xcode 9.3.1 from 8 and have these errors:

Expected method to read dictionary element not found on object of type 'id<NSCopying>'

My code is:

// 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),
};

Can anyone point me in the right direction? I have bolded the errors in the code.

tryKuldeepTanwar
  • 3,490
  • 2
  • 19
  • 49
BTVC
  • 1

2 Answers2

1

The compiler thinks that options is of type id<NSCopying>, not an NSDictionary *, which is required to use the dictionary[key] syntax. Your code snippet does not include where that is declared, which is where the error would be.

Carl Lindberg
  • 2,902
  • 18
  • 22
0

You must cast your object options

    // 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),
};
K-AnGaMa
  • 66
  • 3