【问题标题】:Unrecognized selector sent to class runtime error无法识别的选择器发送到类运行时错误
【发布时间】:2019-06-14 14:45:04
【问题描述】:

我正在使用第三方框架,其中包含 NSData 上的一个类别,并在其中包含一个静态方法 dataUsingBase64String:。 该框架链接良好,代码构建成功。但是当这个方法被调用时我得到unrecognized selector sent to class运行时错误。

我还尝试在 XCode 的 OTHER_LINKER_FLAGS 中添加 -ObjC,-all_load 标志,但没有成功。

【问题讨论】:

    标签: ios objective-c xcode objective-c-category


    【解决方案1】:

    我猜你的库是静态链接的。一个常见的问题是类别不包括或链接。您还需要将 -all_load 添加到使用您的静态库的目标的其他链接器标志中。

    同时检查以下与您的问题相似的答案

    答案 1 - NSData Unrecognized selector sent to class

    答案 2 - Objective-C Category Causing unrecognized selector

    答案 3 - "unrecognized selector sent to instance" to a static library despite ObjC flag

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      注意:我需要以这种方式添加框架,

      Framework Search Paths instead of adding frameworks to "Linked Frameworks and Libraries" section

      在这里,不知何故,即使在添加-Objc-all_load 之后,框架也没有加载。

      最后,OTHER_LINKER_FLAGS 中的-framework 为我解决了问题。

      手册页上的一些内容,

      -framework name[,suffix]
                       This option tells the linker to search for `name.frame-
                       work/name' the framework search path.  If the optional suffix
                       is specified the framework is first searched for the name
                       with the suffix and then without (e.g. look for `name.frame-
                       work/name_suffix' first, if not there try `name.frame-
                       work/name').
      

      【讨论】:

        【解决方案3】:

        如果-Objc不生效,可以尝试从项目中删除你的Category再拖到项目中,勾选Target members。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-04-04
          • 1970-01-01
          • 1970-01-01
          • 2018-03-25
          相关资源
          最近更新 更多