Why does adding 'dynamic' fix my bad access issues?

后端 未结 2 1957
不思量自难忘°
不思量自难忘° 2020-12-28 13:23

I\'m having a strange issue that appeared with iOS 8 Beta 5 (this issue did not occur with previous versions).

I tried to create an empty project and try to replica

2条回答
  •  生来不讨喜
    2020-12-28 13:50

    From Swift Language Reference (Language Reference > Declarations > Declaration Modifier)

    Apply this modifier to any member of a class that can be represented by Objective-C. When you mark a member declaration with the dynamic modifier, access to that member is always dynamically dispatched using the Objective-C runtime. Access to that member is never inlined or devirtualized by the compiler.

    Because declarations marked with the dynamic modifier are dispatched using the Objective-C runtime, they’re implicitly marked with the objc attribute.

    It means that your property/method can be accessed by Objective-C code or class. Normally it happens when you sub-classing a Swift class of Objective-C base class.

提交回复
热议问题