Using 3rd party framework (Alamofire) in my sub-project (CocoaTouch framework)

半城伤御伤魂 提交于 2019-12-14 02:26:38

问题


I am using XCode 8 + Swift 3.

I created a fresh iOS project named "MyApp".

Then, I create a Cocoa touch framework project, named "MySubProject". (The idea is to have MyApp project accessing MySubProject code.)

I added MySubProject into MyApp project, linked the MySubProject framework.

In XCode project navigator it looks like this:

MyApp
  > MySubProject.xcodeproj

Everything works fine. Code in MyApp can access code in MySubProject.

Now, I need to add Alamofire into MySubProject. I followed instruction in Alamofire offical website to manually add Alamofire to MySubProject, the project structure then looks like this:

MyApp
  > MySubProject.xcodeproj
     > Alamofire.xcodeproj

So, MySubProject has dependency on Alamofire framework. This is what it looke like under MySubProject target--> General :

After that, I can access Alamofire in MySubProject code, no compile error. MyApp is Built successfully. However, when I run my app in emulator, I got run-time error:

dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: /Users/myname/Library/Developer/Xcode/DerivedData/MyApp-hezjlyvzxnavccenabxdepgftbrg/Build/Products/Debug-iphonesimulator

/Alamofire.framework/Alamofire Reason: image not found

Why? & How to solve that?


回答1:


I had the same problem here with installation of cocoapods to use alamofire. A solutionthat did work for me was download Alamofire from github, then I compiled the framework of alamofire with xcode and used it in my app. When I put alamofire in my work area I got an error so I had to put alamo xcode project into there too. This way it works for me.




回答2:


If you want to use alamofire, there's a better way to install it. You can use the cocoapods for intall 3rd party frameworks. So, you must follow these steps:

1.- Please install cocoapods by gems sudo gem install cocoapods

2.- Go to your folder by terminal and type pod init, then type vim Podfile

3.- You can see a file that you can add your 3rd party frameworks so you must add Alamofire to your target and write it from your vim :wq. For example type this:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'YourTarget' do
use_frameworks!

pod 'Alamofire', '~>4.0'

4.- Now you must to type pod install from your terminal and that's it. Open your xcworkspace generated from cocoapods and type cmd + B from xCode. Then after that you can import Alamofire to your classes.



来源:https://stackoverflow.com/questions/45307258/using-3rd-party-framework-alamofire-in-my-sub-project-cocoatouch-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!