Using Cocoapods in an App Extension Using a Framework

Using Cocoapods in an app extension using a framework

So, what gives :

  • My concern of "separating pods between targets" is absurd because you can still import them anywhere.
  • The "you have to manually link" issue is fixed by an easy import RealmSwift statement.

The fixed and working Podfile therefore is :

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
pod 'Eureka', '~> 2.0.0-beta'
pod 'PKHUD', '~> 4.0'
pod '1PasswordExtension', '~> 1.8'
end

target 'MyAppKit' do
pod 'Fuzi', '~> 1.0'
pod 'RealmSwift', '~> 2.0'
pod 'Alamofire', '~> 4.0'
pod 'KeychainAccess', '~> 3.0'
pod 'Result', '~> 3.0'

target 'MyAppWidget' do
inherit! :search_paths
end
end

And that's it. I would say that the old behaviour was more obvious and didn't require reading up on "podfile target inheritance". I did learn a lot though. Cheers!

How to import a Cocoapod into an App Extension?

Check this pod file code as example, this pod file have 2 targets the app and the extension.

platform :ios, '9.0'
use_frameworks!
workspace 'MyWorkSpaceApp'

target 'MyApp' do

pod 'SwiftyUserDefaults'
pod 'Alamofire', '~> 4.0'
pod 'AlamofireImage', '~> 3.1'
#pod 'AlamofireNetworkActivityIndicator', '~> 2.0'
#pod "youtube-ios-player-helper", "~> 0.1.6"
#pod 'Alamofire-SwiftyJSON'
pod 'SwiftyJSON', '~> 3.0.0'
#pod 'SlideMenuControllerSwift'
pod 'UIColor_Hex_Swift', '~> 3.0.2'
#pod 'ALLoadingView', :git => 'https://github.com/ALoginov/ALLoadingView.git', :branch => 'swift3'
pod 'SDWebImage', '~>3.8'
#pod 'SwiftSpinner', :git => 'https://github.com/icanzilb/SwiftSpinner.git', :branch => 'swift3'
#pod 'SideMenu'
#pod 'Fabric'
#pod 'Crashlytics'
#pod 'IQKeyboardManagerSwift', '4.0.6'
#pod 'AELog'
#pod 'TestFairy'
#pod "AwesomeCache", "~> 5.0"
#pod 'Deviice'
#pod 'MKDropdownMenu'
#pod "HanekeSwift", :git => 'https://github.com/Haneke/HanekeSwift.git', :branch => 'feature/swift-3'
pod 'OneSignal', '~> 2.4'

post_install do |installer|
puts("Update debug pod settings to speed up build time")
Dir.glob(File.join("Pods", "**", "Pods*{debug,Private}.xcconfig")).each do |file|
File.open(file, 'a') { |f| f.puts "\nDEBUG_INFORMATION_FORMAT = dwarf" }
end
end

target 'MyAppExtension' do
pod 'OneSignal', '~> 2.4'
end

end

I hope this helps you, best regards

Use Cocoapods with an App Extension

The proper way to do this is to update your podfile to add just 1 line :

link_with 'yourApp', 'yourAppExtension'

and a pod update should resolve the issue.

adding a pod to a universal framework library using cocoapods

Here is my whole procedure

  1. crate a new swift app project.
  2. create a new cocoa touch framework target.
  3. in the project directory , run pod init
  4. Tyr This Podfile

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

    target 'SOQ' do
    use_frameworks!
    end

    target 'SOQFW' do
    use_frameworks!
    end

    pod 'EVReflection'

after pod install, in both my two targets SOQ (swift app) and SOQFW (cocoa touch framework) can import EVReflection in *.swift and user class EVObject without a problem.

sample code is

import EVReflection

class User: EVObject {
var id: Int = 0
var name: String = ""
var friends: [User]? = []
}

you can give it a try.

My development environment is os x 10.12 , xode 8.2.1 , cocoapods 1.1.1



Related Topics



Leave a reply



Submit