简体   繁体   English

CocoaPods 如何将Podfile中Framework的自定义子类添加到CocoaPods框架中

[英]CocoaPods How to add a custom Subclass of a Framework in a Podfile to a CocoaPods framework

I am trying to subclass AFHTTPRequestOperation from AFNetworking for error handling in an SDK I am creating for an API.我想继承AFHTTPRequestOperation从AFNetworking用于错误处理在SDK我创建了一个API。 The subclasses are created in the Pod/Classes folder in Finder where the other .h and .m files of mine from my CocoaPods framework are stored.子类在 Finder 的 Pod/Classes 文件夹中创建,我的 CocoaPods 框架中的其他 .h 和 .m 文件存储在该文件夹中。 The framework was created per this method http://guides.cocoapods.org/making/using-pod-lib-create.html .该框架是按照这种方法创建的http://guides.cocoapods.org/making/using-pod-lib-create.html

When I attempt to create a new Cocoa Touch Class as a subclass of the aforementioned AFNetworking classes and add its corresponding .h and .m files to the Pods/Classes destination, I get these errors:当我尝试创建一个新的 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

If I create the subclasses outside of the Pods target and in the target of an XCode project that I have installed my pods framework in, there are no errors.如果我在 Pods 目标之外以及在我安装了 pods 框架的 XCode 项目的目标中创建子类,则不会出现错误。 Because it works in this case, I am assuming that my subclasses in Pod/Classes folder that are a part of my CocoaPods framework do not have access to the AFNetworking framework that is incorporated via the Podfile.因为它在这种情况下有效,所以我假设作为 CocoaPods 框架一部分的 Pod/Classes 文件夹中的子类无法访问通过 Podfile 合并的 AFNetworking 框架。

Would love some help!希望得到一些帮助!

You definitely don't want to be creating subclasses where your CocoaPods are because it could lead to problems when you're installing/updating the pods.您绝对不想在 CocoaPods 所在的位置创建子类,因为它可能会在您安装/更新 Pod 时导致问题。 Keep the subclass in your own project (after all, it is your own file, not theirs).将子类保留在您自己的项目中(毕竟,它是您自己的文件,而不是他们的)。

If you're trying to create a subclass of a public class in the pod, you can create the subclass in your own project.如果您尝试在 pod 中创建公共类的子类,则可以在您自己的项目中创建子类。

If you're trying to create a subclass of a class that's private or internal in the pod, I'd first recommend evaluating whether this is both functionality you want to add and that this is the design pattern you want to use.如果您尝试在 pod 中创建私有或内部类的子类,我建议首先评估这是否是您要添加的功能以及这是否是您要使用的设计模式。 If you decide yes to both, you should create a fork of the repo, make the changes you want in your fork, then update your Podfile to use your forked version of the pod.如果您对两者都决定是,您应该创建 repo 的一个分支,在您的分支中进行您想要的更改,然后更新您的 Podfile 以使用您的 Pod 的分支版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM