Vaisakh KP
Vaisakh KP

Reputation: 497

Access pod inside a custom cocoapod

This is a custom cocoapod which connect with Alamofire. How can i access Alamofire pod imported in my code.

let SDKConnect = Networking()
class Networking {

var AFManager = Alamofire.SessionManager()
init() {
    AFManager = {
        let trustPolicies: [String: ServerTrustPolicy] = [ "example.com": .disableEvaluation ]
        let AFConfig = URLSessionConfiguration.default
        AFConfig.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
        AFConfig.timeoutIntervalForRequest = 15
        AFConfig.timeoutIntervalForResource = 15
        let manager = Alamofire.SessionManager( configuration: URLSessionConfiguration.default, serverTrustPolicyManager: ServerTrustPolicyManager(policies: trustPolicies) )
        return manager
    }()
}

Use of unresolved identifier 'Alamofire'

Pod structure

Target membership

Upvotes: 0

Views: 154

Answers (2)

Philip Niedertscheider
Philip Niedertscheider

Reputation: 1069

I attached a given example and here is the guide on how to create it:

Project:

  • pod lib create WebConnnect to create the initial project (go with the default answers).
  • Run pod deintegrate in the Examples folder, to remove the initial dependencies from the Xcode workspace
  • Add the following code to the WebConnect.podspec:

Pod::Spec.new do |s| ...
s.dependency 'Alamofire' s.dependency 'SwiftyJSON' end

  • Remove the version numbers for Nimble, Quick, FBSnapshotTestCase and Nimble-Snapshots in the Podfile, as these are outdated by default anyway.
  • Now run pod install and pod update, to ensure the newest dependencies are installed.

Code:

Rename the file ReplaceMe.swift to Networking.swift in the folder Development Pods/WebConnect and make sure its Target Membership is the target WebConnect.

Now add the following code to the file (it is basically yours, but I added the import of Alamofire):

import Alamofire

let SDKConnect = Networking()
class Networking {

    var AFManager = Alamofire.SessionManager()
    init() {
        AFManager = {
            let trustPolicies: [String: ServerTrustPolicy] = [ "example.com": .disableEvaluation ]
            let AFConfig = URLSessionConfiguration.default
            AFConfig.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
            AFConfig.timeoutIntervalForRequest = 15
            AFConfig.timeoutIntervalForResource = 15
            let manager = Alamofire.SessionManager( configuration: URLSessionConfiguration.default, serverTrustPolicyManager: ServerTrustPolicyManager(policies: trustPolicies) )
            return manager
        }()
    }
}

Download: Hosted by WeTransfer

Upvotes: 2

Andrey Chernukha
Andrey Chernukha

Reputation: 21808

In the .podspec file of your custom pod add Alamofire as a dependency, something like this:

spec.dependency 'Alamofire'

and then do pod repo push, then pod update YourCustomPod and then you'll be able to use Alamofire

Upvotes: 1

Related Questions