模拟器中的@_dynamicReplacement(for:)错误 [英] @_dynamicReplacement(for: ) error in simulator

查看:193
本文介绍了模拟器中的@_dynamicReplacement(for:)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CocoaPods管理我的私有组件。现在,我有一个组件 Test 。其中一个类的声明如下:

I use CocoaPods to manage my private components. Now I have a component Test. The declaration of one of the classes is as follows:

open class Test {

    open dynamic func test() {
        print("test")
    }
}

我对此组件没有问题,它已经存在于我的私人仓库中

I have no problems with this component, it is already in my private repo

现在我还有一个名为<$ c $的组件c> Test2 。我想在 Test2 中使用 @_ dynamicReplacement(for:)交换 test() 测试中的方法如下:

Now I have another component called Test2. I want to use @_dynamicReplacement(for:) in Test2 to exchange the test() method in Test as follows:

public extension Test {

    @_dynamicReplacement(for: test())
    public func test2() {
        print("test2")
    }
}

现在我想将Test2打包为Pod组件,例如Test。

Now I want to package Test2 as a pod component, like Test.

但是当我执行 pod spec lint 时,它报告一个错误:

But when I execute pod spec lint, it reports an error:

<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: unsupported relocation with subtraction expression, symbol '_$s9MBCRouter6RouterC23MBCNavigationController0cdB010NavigationORszrlE15navigationTest2yyF' can not be undefined in a subtraction expression






我发现此问题仅出现在 x86_64上 i386 上。

我试图创建一个集成了测试 Test2

I tried to create a project that integrates both Test and Test2.

在真实计算机上运行时,效果很好。但是当我在模拟器上运行它时,它会报告错误!

When I run it on a real machine, it works fine. But when I run it on the simulator, it reports an error!

当我将第二段代码放在Test组件中时,

When I placed the second piece of code above in the Test component, it worked without any problems.

因此,我认为需要以下两个条件来重现此错误:

So I think the following two conditions are needed to reproduce this bug:


  1. pod B 中,使用 @_ dynamicReplacement(for:)交换其他Pod中的方法组件

  2. 在模拟器中运行项目

  1. In pod B, use @_dynamicReplacement(for:) to swap methods in other pod components
  2. Run the project in the simulator

我发现了这个问题,但是我可以解决不了,任何人都可以帮助解决这个问题吗?

I found this problem, but I can't solve it, can anyone help to solve this problem? thank you very much!

最后,我想谈谈我的开发环境

Finally, I want to talk about my development environment


  1. 我使用CocoaPods 1.9.1,Xcode 11.4和Swift 5.2。

  2. use_frameworks!用于podfile

  3. Test Test2 <$设置为 static_framework = true

  1. I use CocoaPods 1.9.1, Xcode 11.4 and Swift 5.2.
  2. Only use_frameworks! is used in the podfile
  3. Test and Test2 .podspec files with set static_framework = true


推荐答案

要为模拟器进行构建,您需要在函数声明中添加 @objc 属性,例如:

To build for Simulator you need add @objc attribute to a function declaration e.g:

open class Test {

    open @objc dynamic func test() {
        print("test")
    }
}

更新:更常见的解决方案(包括泛型)-设置<在构建设置中将strong>编译模式更改为增量,在这种情况下,您根本不需要使用 @objc 模拟器。

UPDATE: More common solution (included Generics) - set Compilation Mode to Incremental in Build Settings and in this case you don't need to use @objc at all for the Simulator.

这篇关于模拟器中的@_dynamicReplacement(for:)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆