RestKit 和 CocoaLumberjack 作为框架集成在 Xcode7 中

RestKit and CocoaLumberjack integrated as frameworks in Xcode7

我正在开发一个同时使用 RestKit 和 CocoaLumberjack 的项目。该项目还使用了其他一些 pods,其中一些只存在于 swift 中。我使用 cocoapods 0.38.2 进行依赖管理,我的 podfile 看起来像这样(为了便于阅读删除了其他 pods):

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
use_frameworks!

pod 'RestKit'
pod 'CocoaLumberjack'

我需要使用 use_frameworks!,因为其他 pods 是 swift-only。我尝试使用 Xcode7 beta 5 编译它,但出现以下错误:

"_OBJC_CLASS_$_DDLog", referenced from:

  objc-class-ref in RKLumberjackLogger.o

ld: symbol(s) not found for architecture x86_64

所以我查看了有问题的文件并发现了这个:

#if __has_include("DDLog.h")
#import "RKLumberjackLogger.h"
#import "DDLog.h"

如果 DDLog.h 不存在,看起来整个文件都没有解析,在这种情况下,我认为 RestKit 日志记录回落到 NSLog 或其他。否则,使用 Lumberjack 日志记录,这就是我想要的。

经过一些调查,我怀疑 RestKit 以某种方式看到了 CocoaLumberjack headers(DDLog.h 所在的位置),但在项目时没有正确地 link 反对它建成。如果您有更好的想法,请随意质疑,但我可以确认转到 CocoaLumberjack 源代码并手动添加 DDLog.m 作为 RestKit 框架目标的成员可以让我正确编译项目。

所以,我的问题是,解决这个问题的正确方法是什么? RestKit 并不直接依赖于 CocoaLumberjack,而是尝试检测它并在可能的情况下使用它,但失败得很惨。有没有办法从我的项目级别使用 Lumberjack link RestKit,这样我就不必修改 pods?

可以找到示例项目here

你的猜测是正确的。

RestKit somehow sees the CocoaLumberjack headers (where the DDLog.h is), but is not properly linked against it when the project is built

这是一个带有 RestKit 的 problem,您在自己的项目中所做的一切都是一种变通方法。所以可以说,在你的项目中没有单一的正确方法来解决这个问题。

我已经提交了一个 Pull Request 来解决这个问题。


更新:

拉取请求已合并,但在撰写此更新时,尚未发布新版本的 RestKit。

pod "RestKit", :head, :subspecs => ['Core', 'CocoaLumberjack']

RestKit 的 Lumberjack 日志记录功能已移至单独的子规范中,如果要使用它必须指定。 :head 将告诉 CocoaPods 使用当前主版本而不是已发布的版本。