Firebase with Swift

1,066 views
Skip to first unread message

Joe Fiorini

unread,
Jun 3, 2014, 10:40:36 AM6/3/14
to fireba...@googlegroups.com
Last night I started building an iOS app with Swift that connects to a Firebase backend. I wanted to use the Firebase iOS SDK, but according to the Using Swift with Cocoa and Objective-C documentation, that requires a build setting change in the Firebase SDK itself. Since I didn't have access to that source, I needed another approach. As I was just on the cusp of writing my own wrapper around the REST API, I realized that I could probably create my own headers that import the Firebase SDK and access it that way. Following the instructions from the afore-linked document, I created a "bridging header" that's meant to import Objective-C code into Swift modules, and put #include <Firebase/Firebase.h> at the top. That was all I had to do, I had total access to the Firebase class and all of its types in Swift. Within a couple more hours I had data from Firebase rendering in a UICollectionView in my app.

I've pushed the code I have so far to https://github.com/joefiorini/PunchCards-iOS. I still have a lot of work to do, but this is a start.

Michael Wulf

unread,
Jun 3, 2014, 2:02:52 PM6/3/14
to fireba...@googlegroups.com
Talk about some cutting edge work! Great stuff.

I'll put a task in the system to see how we could support Swift without the additional bridge. In the mean time, keep us updated on your progress.

Cheers,


On Tue, Jun 3, 2014 at 7:40 AM, Joe Fiorini <g...@joefiorini.com> wrote:
Last night I started building an iOS app with Swift that connects to a Firebase backend. I wanted to use the Firebase iOS SDK, but according to the Using Swift with Cocoa and Objective-C documentation, that requires a build setting change in the Firebase SDK itself. Since I didn't have access to that source, I needed another approach. As I was just on the cusp of writing my own wrapper around the REST API, I realized that I could probably create my own headers that import the Firebase SDK and access it that way. Following the instructions from the afore-linked document, I created a "bridging header" that's meant to import Objective-C code into Swift modules, and put #include <Firebase/Firebase.h> at the top. That was all I had to do, I had total access to the Firebase class and all of its types in Swift. Within a couple more hours I had data from Firebase rendering in a UICollectionView in my app.

I've pushed the code I have so far to https://github.com/joefiorini/PunchCards-iOS. I still have a lot of work to do, but this is a start.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Conrad Taylor

unread,
Jun 6, 2014, 3:03:34 AM6/6/14
to fireba...@googlegroups.com


On Tuesday, June 3, 2014 7:40:36 AM UTC-7, Joe Fiorini wrote:
Last night I started building an iOS app with Swift that connects to a Firebase backend. I wanted to use the Firebase iOS SDK, but according to the Using Swift with Cocoa and Objective-C documentation, that requires a build setting change in the Firebase SDK itself. Since I didn't have access to that source, I needed another approach. As I was just on the cusp of writing my own wrapper around the REST API, I realized that I could probably create my own headers that import the Firebase SDK and access it that way. Following the instructions from the afore-linked document, I created a "bridging header" that's meant to import Objective-C code into Swift modules, and put #include <Firebase/Firebase.h> at the top. That was all I had to do, I had total access to the Firebase class and all of its types in Swift. Within a couple more hours I had data from Firebase rendering in a UICollectionView in my app.

I've pushed the code I have so far to https://github.com/joefiorini/PunchCards-iOS. I still have a lot of work to do, but this is a start.

Joe, could you tell me about your software configuration?  For example, are you using OSX 10.10 with Xcode 6?  I attempted to compile the project but it seems that Firebase SDK is missing from the project.

Michael Wulf

unread,
Jun 6, 2014, 10:15:06 AM6/6/14
to fireba...@googlegroups.com
Conrad,

Did you download the SDK separately or install via Maven? I don't see it in the GitHub project, so that step would be a DIY.

HTH,


--

Michael Wulf

unread,
Jun 6, 2014, 11:29:30 AM6/6/14
to fireba...@googlegroups.com
Err, Conrad, sorry about that. Was in my alternate universe again where .h and .java mean the same thing, also known as The Land Without Coffee.

Roughly the same suggestion, but maybe with this link to grab the lib.

Conrad Taylor

unread,
Jun 6, 2014, 1:28:53 PM6/6/14
to fireba...@googlegroups.com
Hi, I'm still seeing the following issue after bringing in the Firebase iOS SDK.

Inline image 2




You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/m7vDEdF_lf4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Think different and code well,

-Conrad

Jake Johnson

unread,
Jun 9, 2014, 7:34:17 AM6/9/14
to fireba...@googlegroups.com
Hello, 

I originally had some trouble with this as well and asked a question over at SO: http://stackoverflow.com/questions/24093463/firebase-with-swift

I eventually got it to work and wrote a short blog post with simple steps on how to get it done: http://drex.svbtle.com/writing-a-swift-app-with-firebase

Additionally I ported the firechat-ios app to Swift as a proof of concept: https://github.com/johnsonjake/SwiftChat

Hopefully that should help everyone who is currently having difficulty getting Swift set up with Firebase.

Regards,

Michael Wulf

unread,
Jun 9, 2014, 9:42:36 AM6/9/14
to fireba...@googlegroups.com
Great stuff, Jake! Thanks so much for sharing this with the community.

Sean Durham

unread,
Jun 11, 2014, 1:30:27 PM6/11/14
to fireba...@googlegroups.com
I see the same error Conrad Taylor sees when building both SwiftChat and a new project. "Undefined symbols for architecture i386"
Have you made any progress on this Conrad? Anyone else running into this problem?


On Tuesday, June 3, 2014 7:40:36 AM UTC-7, Joe Fiorini wrote:

Conrad Taylor

unread,
Jun 12, 2014, 10:03:17 AM6/12/14
to fireba...@googlegroups.com
Sean, I'm had great success compiling in the iOS Simulator for 64 bit devices like iPhone 5s, iPad Air, Resizable iPhone, and Resizable iPad.  Next, Apple recommends compiling application code and 3rd party libraries for 64 bit.  For more information, please see WWDC 2014 session, 417 - What's New in LLVM, where they go into much greater detail.


--
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/m7vDEdF_lf4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Karen Ho

unread,
Jun 19, 2014, 1:57:21 PM6/19/14
to fireba...@googlegroups.com
I'm getting the same error as both Conrad and Sean (even with just downloading and trying to build Jake's swiftchat)

Undefined symbols for architecture i386:
   "_fwrite$UNIX2003", referenced from:
      leveldb::(anonymous namespace)::PosixEnv::~PosixEnv() in Firebase(env_posix.o)

I have the following libraries linked:
libc++.dylib
SystemConfiguration.framework
libicucore.dylib
Security.framework
CFNetwork.framework
Firebase.framework

and under other linker flags is -ObjC

Has anyone been able to find a solution to the above error? Thanks.

k...@firebase.com

unread,
Jun 19, 2014, 2:51:57 PM6/19/14
to fireba...@googlegroups.com
Hi all,

We know about this error, and we're working on getting out a release that will solve this issue.

-- Katherine

k...@firebase.com

unread,
Jun 26, 2014, 6:40:28 PM6/26/14
to fireba...@googlegroups.com
We've pushed out a new version of the framework that addresses the _fwrite$UNIX2003 issue. Now, the code should compile with all the devices, and not just the 64-bit devices. Grab a new version on the downloads page!

You will still need to create a bridging header to import Firebase into Swift code, though.

- Kat

Jom Pin

unread,
Feb 14, 2015, 6:45:14 PM2/14/15
to fireba...@googlegroups.com
Hi everyone,

I am new to firebase.

So if i want to use ios swift, only way is to do bridging? Will I get any performance issue or not really enjoy the power of swift?

I have picked up swift, but not really into objective-c.

Is the bridging able to do alot with swift?

Else, should i consider phonegap with firebase?

Any help? Thanks.

Conrad Taylor

unread,
Feb 15, 2015, 11:33:57 AM2/15/15
to fireba...@googlegroups.com
Jom, I would recommend using the bridging header.  Otherwise, you can use the Firebase REST API.  Please review the following two links:



For more options, visit https://groups.google.com/d/optout.

Derek Abram

unread,
Oct 23, 2015, 4:57:00 PM10/23/15
to Firebase Google Group
Follow this approach works for me, but if I want to use another pod and need use_frameworks! it breaks the firebase implementation. Is there a way to use both firebase and another framework?
Message has been deleted

Mike Mcdonald

unread,
Oct 23, 2015, 6:56:22 PM10/23/15
to Firebase Google Group
Derek,

Which version of the pod are you using, and what other pod(s) is/are you using?

It's going to depend on 1) the version of the Firebase client you're using and 2) the other pod(s). There are some known weird issues with transitive dependencies (between static and dynamic libraries), so that info can help us create a best path forward for you.

Thanks,
--Mike

Derek Abram

unread,
Oct 26, 2015, 2:00:18 PM10/26/15
to Firebase Google Group
The main pods I need are the Facebook ones. This is the pod file I'd like to be able to use:

pod 'Firebase', '>=2.3.2'


pod 'FBSDKCoreKit'

pod 'FBSDKLoginKit'

pod 'FBSDKShareKit'


use_frameworks!

Mike Mcdonald

unread,
Oct 28, 2015, 6:21:38 AM10/28/15
to Firebase Google Group
I would change it to '~> 2.4' since I know that 2.4.2 should be good to go. Also, are you also targeting iOS 7, or is this 8.0+?

When you say it breaks, can you post the exact Cocoapods error?

Thanks,
--Mike
Reply all
Reply to author
Forward
0 new messages