Stack overflow when defining subscript on CKRecord in Swift

前端 未结 3 1141
有刺的猬
有刺的猬 2021-01-18 12:22

This question asks whether one can use subscripting with CKRecord in Swift. While I already knew how to do what the questioner wanted, every permutation of it g

3条回答
  •  再見小時候
    2021-01-18 13:19

    After some testing and debugging (via a subclass), I discovered that, for CKRecord, objectForKey: does indeed call objectForKeyedSubscript:. Also, implementing subscript in a Swift class that is marked @objc implicitly (by descending from NSObject) or explicitly means that subscript is implemented as objectForKeyedSubscript:.

    This means that implementing subscript on CKRecord in an extension hides the default implementation, which causes the stack overflow.

提交回复
热议问题