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

问题描述 投票:0回答:1

我正在尝试从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目标之外以及在我已安装Pod框架的XCode项目的目标中创建子类,则不会出现错误。因为在这种情况下它可以工作,所以我假设作为CocoaPods框架一部分的Pod / Classes文件夹中的子类无法访问通过Podfile合并的AFNetworking框架。

希望得到一些帮助!

ios architecture frameworks subclass cocoapods
1个回答
1
投票

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

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

如果您要创建Pod中私有或内部类的子类,我首先建议评估这是您要添加的功能,还是您要使用的设计模式。如果两者都选择,则应创建一个仓库的分支,在分支中进行所需的更改,然后更新Podfile以使用分支的分支版本。

© www.soinside.com 2019 - 2024. All rights reserved.