Building a Cocoapod with Swift and dependency on Objective-C framework
I finally found another thread on SO dealing with similar problems: Linker errors in a Swift project with Google Maps for iOS added via CocoaPods.
It appears that the errors were due to a combination of bad Podspec file (on the Google Maps iOS SDK side), and bugs in Cocoapods 0.36 Beta.
It's actually possible to workaround the issues by using @fz.'s revised Podspec file for Google Maps: https://stackoverflow.com/a/28471830/145997. Another article that also was of great interest to understand how the vendored_frameworks
setting works in Podspec
is: http://codereaper.com/blog/2014/creating-a-pod-with-crashreporter/.
So, to correctly import the Google Maps iOS SDK in a Pod project, first use the following Podfile
:
source 'https://github.com/CocoaPods/Specs.git'platform :ios, '8.0'# altered version of Google's Podspecpod 'Google-Maps-iOS-SDK', :podspec => "https://raw.githubusercontent.com/Reflejo/GoogleMapsPodspec/master/Google-Maps-iOS-SDK.podspec.json"use_frameworks! # don't forget this!
I'm now able to reference Google Maps classes from my Swift code simply by doing import GoogleMaps
. And, to distribute the Pod, my final Podspec
now resembles the following:
Pod::Spec.new do |s| s.name = 'MyPod' s.version = '1.0.0' s.homepage = "https://github.com/..." s.summary = '(pod summary)' #s.screenshot = "" s.author = { 'Romain L' => '(email)' } s.license = { :type => 'BSD', :file => 'LICENSE' } s.social_media_url = "https://twitter.com/_RomainL" s.platforms = { :ios => '8.0' } s.ios.deployment_target = '8.0' s.source_files = 'MyCode/*.{h,swift}' s.module_name = 'MyPod' s.source = { :git => "https://github.com/....git", :tag => "1.0.0" } s.requires_arc = true s.libraries = "c++", "icucore", "z" # required for GoogleMaps.framework s.frameworks = "AVFoundation", "CoreData", "CoreLocation", "CoreText", "Foundation", "GLKit", "ImageIO", "OpenGLES", "QuartzCore", "SystemConfiguration", "GoogleMaps" # required for GoogleMaps.framework s.vendored_frameworks = "Dependencies/GoogleMaps.framework" # Put the Google-provided framework in that subfolder of your Pod project #s.dependency 'Google-Maps-iOS-SDK' # Careful! this will cause errors if enabled!end
I am now able to start a new iOS app in Xcode and use the following Podfile
to link against my own pod, itself referencing the Google Maps iOS SDK:
source 'https://github.com/CocoaPods/Specs.git'platform :ios, '8.0'pod 'MyPod'use_frameworks! # do not forget this!
Not that easy, but feasible after all! Hoping Google will soon patch its Podspec
file for Swift developments, though.