[英]CocoaPods How to add a custom Subclass of a Framework in a Podfile to a CocoaPods framework
我想繼承AFHTTPRequestOperation
從AFNetworking用於錯誤處理在SDK我創建了一個API。 子類在 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 項目的目標中創建子類,則不會出現錯誤。 因為它在這種情況下有效,所以我假設作為 CocoaPods 框架一部分的 Pod/Classes 文件夾中的子類無法訪問通過 Podfile 合並的 AFNetworking 框架。
希望得到一些幫助!
您絕對不想在 CocoaPods 所在的位置創建子類,因為它可能會在您安裝/更新 Pod 時導致問題。 將子類保留在您自己的項目中(畢竟,它是您自己的文件,而不是他們的)。
如果您嘗試在 pod 中創建公共類的子類,則可以在您自己的項目中創建子類。
如果您嘗試在 pod 中創建私有或內部類的子類,我建議首先評估這是否是您要添加的功能以及這是否是您要使用的設計模式。 如果您對兩者都決定是,您應該創建 repo 的一個分支,在您的分支中進行您想要的更改,然后更新您的 Podfile 以使用您的 Pod 的分支版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.