Why can the keyword “weak” only be applied to class and class-bound protocol types

后端 未结 11 1332
清酒与你
清酒与你 2020-12-13 03:14

When I\'m declaring variables as weak in Swift, I sometimes get the error message from Xcode:

\'weak\' may only be applied to class and

11条回答
  •  半阙折子戏
    2020-12-13 04:10

    I tried to capture String and Array-typed properties for a closure. I got these errors:

    'weak' may only be applied to class and class-bound protocol types, not '[String]'

    'weak' may only be applied to class and class-bound protocol types, not 'String'

    I played a while in the playground, and it turned out, capturing self is enough for these types.

提交回复
热议问题