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
- crate a new swift app project.
- create a new cocoa touch framework target.
- in the project directory , run
pod init
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
How to Pass Swift Enum with @Objc Tag
How to Restrict the iOS App Only for iPhone Excluding iPad
Detect Tap on Calloutbubble in Mkannotationview
External Framework File/File.H (Parse/Parse.H) File Not Found
Full Resolution Screenshots for iPhone 6 and 6+
Zip and Unzip a File Programmatically in iOS
How to Make Uipageviewcontroller Reuse Controller Like Tableview Reuse Cell
Setneedsdisplayinrect: Causes the Whole View to Be Updated
Why Is Swiftui Picker in Form Repositioning After Navigation
Core Location Not Working in iOS 8
How to Wait for Method That Has Completion Block (All on Main Thread)
How to Port "Method_Getimplementation" and "Method_Setimplementation" to Monotouch
Apple MACh-O Linker & Ditto Error - Xcode 8
Module 'Alamofire' Has No Member Named 'Request'
To Change the Color of Unselected Uitabbar Icon in iOS 7
How Do Set a Width and Height of an Image in Swift
Pulling Data from a Cmsamplebuffer in Order to Create a Deep Copy