Bulk fix hundreds of “#selector not exposed to Objective-C” errors in Xcode 9 or 9.1

前端 未结 2 1053
星月不相逢
星月不相逢 2021-01-23 11:56

Is there any way to fix multiple errors at once by Adding \'@objc\' to expose this instance method to Objective-C, I actually had over 200 of these errors, after I

2条回答
  •  忘掉有多难
    2021-01-23 12:36

    You can use the @objcMembers attribute on your whole class or struct. You need to choose the classes on which you want to apply the @objcMembers attributes.

    You can follow this tutorial.

    According to Apple doc:

    When a Swift class introduces many new methods or properties that require behavior from the Objective-C runtime, use the @objcMembers attribute in the declaration of that class. Applying the @objcMembers attribute to a class implicitly adds the @objc attribute to all of its Objective-C compatible members. Because applying the @objc attribute can increase the compiled size of an app and adversely affect performance, only apply the @objcMembers attribute on declarations when each member needs to have the @objc attribute applied.

提交回复
热议问题