【问题标题】:CocoaPods How to add a custom Subclass of a Framework in a Podfile to a CocoaPods frameworkCocoaPods 如何将 Podfile 中框架的自定义子类添加到 CocoaPods 框架
【发布时间】:2015-01-19 02:09:06
【问题描述】:

我正在尝试从 AFNetworking 子类化 AFHTTPRequestOperation,以便在我为 API 创建的 SDK 中进行错误处理。子类在 Finder 的 Pod/Classes 文件夹中创建,其中存储了我的 CocoaPods 框架中的其他 .h 和 .m 文件。该框架是根据此方法 http://guides.cocoapods.org/making/using-pod-lib-create.html 创建的。

当我尝试创建一个新的 Cocoa Touch 类作为上述 AFNetworking 类的子类并将其对应的 .h 和 .m 文件添加到 Pods/Classes 目标时,我收到以下错误:

Ld /Users/bryanboyko/Desktop/XCode/1StudentBody_iOS_Framework/Example/Build/Products/Debug-iphonesimulator/OSB-iOS-SDK.bundle/OSB-iOS-SDK normal i386
    cd /Users/bryanboyko/Desktop/XCode/1StudentBody_iOS_Framework/Example/Pods
    export IPHONEOS_DEPLOYMENT_TARGET=7.1
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk -L/Users/bryanboyko/Desktop/XCode/1StudentBody_iOS_Framework/Example/Build/Products/Debug-iphonesimulator -F/Users/bryanboyko/Desktop/XCode/1StudentBody_iOS_Framework/Example/Build/Products/Debug-iphonesimulator -filelist /Users/bryanboyko/Desktop/XCode/1StudentBody_iOS_Framework/Example/Build/Intermediates/Pods.build/Debug-iphonesimulator/OSB-iOS-SDK.build/Objects-normal/i386/OSB-iOS-SDK.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.1 -Xlinker -dependency_info -Xlinker /Users/bryanboyko/Desktop/XCode/1StudentBody_iOS_Framework/Example/Build/Intermediates/Pods.build/Debug-iphonesimulator/OSB-iOS-SDK.build/Objects-normal/i386/OSB-iOS-SDK_dependency_info.dat -o /Users/bryanboyko/Desktop/XCode/1StudentBody_iOS_Framework/Example/Build/Products/Debug-iphonesimulator/OSB-iOS-SDK.bundle/OSB-iOS-SDK

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_AFHTTPRequestOperation", referenced from:
      _OBJC_CLASS_$_OSBRequestOperation in OSBRequestOperation.o
  "_OBJC_CLASS_$_AFHTTPRequestOperationManager", referenced from:
      _OBJC_CLASS_$_OSBRequestOperationManager in OSBRequestOperationManager.o
  "_OBJC_CLASS_$_AFHTTPResponseSerializer", referenced from:
      objc-class-ref in OSBRequestOperation.o
  "_OBJC_METACLASS_$_AFHTTPRequestOperation", referenced from:
      _OBJC_METACLASS_$_OSBRequestOperation in OSBRequestOperation.o
  "_OBJC_METACLASS_$_AFHTTPRequestOperationManager", referenced from:
      _OBJC_METACLASS_$_OSBRequestOperationManager in OSBRequestOperationManager.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

ld: symbol(s) not found for architecture i386

如果我在 Pods 目标之外和在我安装了我的 pods 框架的 XCode 项目的目标中创建子类,则不会出现错误。因为它在这种情况下有效,所以我假设我的 Pod/Classes 文件夹中的子类是我的 CocoaPods 框架的一部分,它们无法访问通过 Podfile 合并的 AFNetworking 框架。

希望得到一些帮助!

【问题讨论】:

    标签: ios architecture frameworks subclass cocoapods


    【解决方案1】:

    您绝对不想在 CocoaPod 所在的位置创建子类,因为这可能会在您安装/更新 pod 时导致问题。将子类保留在您自己的项目中(毕竟,这是您自己的文件,而不是他们的)。

    如果您尝试在 pod 中创建公共类的子类,您可以在自己的项目中创建子类。

    如果您尝试在 pod 中创建私有或内部类的子类,我首先建议您评估这是否既是您想要添加的功能,又是您想要使用的设计模式。如果您对两者都同意,您应该创建一个 repo 的 fork,在您的 fork 中进行您想要的更改,然后更新您的 Podfile 以使用您的分叉版本的 pod。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 2016-06-21
      • 2017-01-17
      相关资源
      最近更新 更多