Google Drive API Bridge for Swift

From a previously deleted entry :

I'm struggling to get the Google Drive API to work with Swift and hope someone has a suggestion. Here is where I am still: I have the Google Drive API installed and it works in Objective-C ...

I am trying to reproduce this example from Google in Swift, but import GTLDrive returns an error in Xcode:

There is no such module 'GTL; DRive.

I cannot use GTLServiceDrive from Swift classes. What combination of CocoaPod + header should I use?

+4
ios swift cocoapods
source share
3 answers

You need 3 things:

(1) Well-formed subfile

 platform :ios, '8.0' target 'GoogleDrive' do pod 'Google-API-Client/Drive', '~> 1.0' end 

(2) Open the Google API through bridging headers

 #import "GTMOAuth2ViewControllerTouch.h" #import "GTLDrive.h" 

(3) GTL reference is not required in the Swift class; DRive

 override func viewDidLoad() { super.viewDidLoad() // ... let service:GTLServiceDrive = GTLServiceDrive() service.authorizer = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName("Drive API", clientID: "YOUR_CLIENT_ID_HERE", clientSecret: "YOUR_CLIENT_SECRET_HERE") // ... } 
+6
source share

I just ran into this in Xcode 7.3 and fixed it in the bridge header:

 #import <GoogleAPIClient/GTLDrive.h> 

Also, if you need some authentication:

 #import <GTMOAuth2/GTMOAuth2ViewControllerTouch.h> 
+2
source share

I completely dropped the Swift Object API C API library and created a workaround: https://github.com/metaprgmr/GoogleApiProxyForSwift . By the way, I used Google Drive as a guinea, where you can find experiments near the end of my presentation on YouTube. Check this.

+1
source share

All Articles