Search code examples
swiftafnetworkingdynamic-library

Swift: Dynamic Library And AFNetworking


I have a problem integrating AFNetworking in my Swift Dynamic Library:

Here is what I have done:

  1. Create Xcode Project: ( Cocoa Touch Framework )
  2. Initialize Pod: ( pod init ) via Terminal
  3. Modify Podfile: Here is the content of the podfile, and execute (pod install)

    target 'MyFramework' do 
    use_frameworks!
    pod 'AFNetworking' => '~>2.0' 
    end
    
  4. Create sample swift file "MyLibrary" with 1 method and property.

  5. Import AFNetworking (import AFNetworking)
  6. Build, and the sample "MyFramework.framework" has been created.
  7. Create a new project file ( single application )
  8. Drag "MyFramework.framework" to the new created project
  9. Import MyLibrary: ( import MyLibrary ) in a viewcontroller class
  10. Build.

Error:

ld: framework not found AFNetworking for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)


Solution

  • You dragged the framework you've built manually into the app project. This way Xcode won't know that it also needs AFNetworking as an additional dependency.

    You have to use CocoaPods instead to add your framework to the app. This way you can declare AFNetworking as a dependency of your framework in it's .podspec file. CocoaPods will then link AFNetworking to the app.

    See