SM654321
SM654321

Reputation: 89

How to install a swift framework which has a cocoapod dependency into your swift app project in Xcode?

I've looked all over for an example on this and couldn't really find something that matches my question/situation.

I have a swift framework called FrameworkA. Within FrameworkA I have placed a cocoapod, Alamofire, by creating a podfile and adding the needed pod information. The podfile is listed next.

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

target 'FrameworkA' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for FrameworkA
  pod 'Alamofire', '~> 5.2'
end

The pod/Alamofire installs correctly as I tested it using a simple call in a test class within FrameworkA. See code:

import Foundation
import Alamofire

class TestClass {
    
    let test = AF.request("https:/google.com").response { response in
        debugPrint(response)
    }
    
}

With everything working, at this point I would like to place FrameworkA inside a Swift App project within Xcode.

This is where I run into a roadblock as i am unable to build a simple app ApplicationA with FrameworkA installed as Alamofire is not found within FrameworkA. See image.

module not found

What I have tried:

I have tried dragging and dropping in FrameworkA's .xcodeproj file into ApplicationA's project within Xcode and then adding the framework to Frameworks, Libraries, Embedded Content section. See images. module drag and drop

enter image description here

When I try to build I get a compile error that FrameworkA cannot find Alamofire. See image:

enter image description here

My main questions is:

Upvotes: 1

Views: 1776

Answers (1)

SM654321
SM654321

Reputation: 89

I was able to answer my own question.

All I had to do was add Alamofire to ApplicationA as a cocoapod and everything builds correctly.

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

target 'ApplicationA' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for ApplicationA
  pod 'Alamofire', '~> 5.2'
end

Upvotes: 2

Related Questions