Connect Firebase to Xcode: A Step-by-Step Tutorial | Firebase Bootcamp #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right so we're going to just jump right in here we're going to start an expo project we're going to start a Firebase project and then we're going to connect Firebase to our xcode project uh so this is actually super simple you guys are going to see that in a couple seconds there's not much code we have to write but I am going to take a couple minutes in this video to kind of just explain at a high level again what is Firebase why are we using it and what are some of the implications of using Firebase in your app all right welcome back everybody it has been such a long time since I have made a video I think 9 or 10 months now so hopefully you guys are still here I'm definitely going to be a little bit Rusty in these first couple videos so bear with me as I get back into the groove but I'm super excited because Firebase is very fun to use and I definitely enjoyed prepping for this course because there's just so much cool stuff that we can do using the Firebase sdks that we can't or would be really difficult to do if we didn't have some sort of SDK like this so for this video we're going to first talk very briefly about what Firebase is what are its capabilities then we're going to start up a project and connect in to Firebase to connect in we're going to use a swift package manager which I don't think I've done on my channel before is basically a super convenient way to add in third-party packages to your xcode project luckily Swift package manager we don't have to use the terminal anymore we can do it straight in xcode super easy so let's get into it firstly what is Google Firebase those of you who are not familiar generally when someone says I'm using Firebase that means they're using Firebase as the back end for their app so Google Firebase is basically like a monstrous SDK that has a bunch of sdks inside of it so as we're going to go through in this course all of these child sdks have different use cases some are for your database some are for analytics crashlytics a b testing a whole bunch of different things someone says I'm using Firebase as my back end it usually just means they're using the database but it is really important to know that you can use Firebase and not use their database and use some of their other products as well so there's a lot of apps out there that actually don't use the Firebase database but use the other tools in Firebase which of course we're going to learn here as well so it's called Google Firebase obviously because Google makes it and that's actually an important thing to understand about Firebase so previously on my channel I have covered core data which is a local database on the iPhone and I've also covered cloudkit which is a remote database on Apple's servers now it's important though to note that both core data and Cloud kit are made by Apple so they are for iOS devices for building iOS application so if you're just building an IOS app and that's the entire use of your project then that's fine but a lot of companies also want to make an Android app or a web app or something along those lines and so if you made an Android app you wouldn't be able to connect it to your Cloud kit database because Cloud kit is specific for Apple products the beautiful thing about Firebase is that you can connect to it from pretty much any device it is purposely made so that iOS apps can connect to it Android apps can connect to it web apps can connect to it we can get all of our apps to connect to this single sort which is extremely convenient and extremely scalable as you're going to see later in this video there's a whole bunch of stuff that Firebase can they're highlighting here the build features includes firestore which is a fully functioning scalable database that you can connect into there's authentication so that's going to handle all of your sign in methods sign in with Apple sign in with Google sign in with email everything like that a bunch of extensions which we'll talk about later in this course they have crash monitoring performance monitoring analytics tools there's remote configs you can literally remotely change configurations in your app Cloud messaging and then a b testing so you can basically monitor some of those remote configurations figure out what's the best configuration for your app we're going to cover pretty much all of this throughout this course we're going to start with the authentication and then move to the database those are the two definitely most common Firebase features and then we're going to move basically to release a monitor and then into engage it is important to note that Firebase is free to start which is great if you're just developing or creating a sample app like what we're going to do but some of their products do require you to upgrade to their paid plan which is a pay-as-you-go plan and then some of the products also require you to have an apple developer account which is not a Firebase thing that is an apple thing we pretty much all the videos in this course though will not require you to actually make a paid account it is important to note though as we start incorporating sdks like this into our projects that we have to be aware of the pricing right so if we use cloud kit or core data there's no extra charge in using that whereas in Firebase we're now going to have to pay for it so if we go to the pricing tab it's very simple start with the spark plan which is free and you get some limits and then pay as you go basically gives you unlimited basically removes the limits and then you pay for your usage as we get into actually using our database we'll be able to see the actual usage for each basically child SDK so here's the authentication package here's the firestore which is their database so basically you can use all of these and then the pricing will aggregate together and it will charge you per month all right that is enough talking let's actually set up a project now all right so let's set this thing up before we actually set up our Firebase project let's set up our xcode project so I'm going to open up xcode real quick I'm going to use version 14.2 they've made a bunch of updates to xcode recently and most of them are good a couple of them are a little iffy but 14.2 seems to be stable let's create a new xcode project it's going to be an app just like all of our other projects of course we're going to do a boot camp here so it's not going to be a functioning app but we're going to do it in app project product name product name I'm going to call this swiftful Firebase bootcamp call it whatever you want to call it put in your organization identifier we're not going to push this to the App Store so it doesn't really matter Swift UI interface language is Swift not going to use core data and don't need tests go on click next save it where you need to save it and once you're done let's open up the xcode project let's get the simulator connected here all right so we got our xcode project set up now let's set up our Firebase project so we're gonna jump back into the internet browser we're gonna go to firebase.google.com and I think you need to be signed into a Google account to do this so I'm signed into mine and let's get started as you're going to see their docs are awesome so even if you didn't have me you would be able to set this up on your own I'm sure of it because their docs are pretty detailed for at least for the big stuff in Firebase so we're going to create a new project here welcome to Firebase create a project let's create a name for your project so this is going to be the name that we use in the Firebase console it does not have to be the exact same name as your app the name that you're going to ship with your bundle you're going to configure an xcode but this will be the name for your project and you cannot change the name once you create it we're going to name this Swift full Firebase bootcamp of course name it what you want accept the terms and continue later in this course we're going to add Google analytics is basically Google's Analytics tool that comes baked in to Firebase and the awesome part is that a lot of the analytics that we want to track are automatically tracked for us so for example first app open when a user first opens your app that's automatically going to be logged to Firebase so we don't have to send those analytics ourselves so of course like they're recommending we want to enable this for our project and click continue my analy Association is going to be in the United States this should be the location of your organization it's not necessarily where your users are but your organization let's use the default settings let's accept the terms let's create the project oh great my new project is ready click continue and it's going to jump us into the Firebase console all right so it's out of this little pop-up here the Firebase console can definitely be overwhelming if you've never used it before but it's actually not that bad so essentially the left side is our Navigator all of the different I'm going to call them like Child sdks So within Firebase you get again like the analytics tools of database tools and you can see all the different tools on the left column here the primary ones are in the build section so this is authentication these are the databases storage is where you can host images and videos and things like that we have the release and monitor section where we have our crashlytics our performance a whole section for all the analytics that we're going to get into and then engage this is stuff that after you've created your app to optimize your app so A B test in-app messaging remote config deep linking adding advertisements into your app so much cool stuff here but we are just going to start by getting our xcode project connected to Firebase and then throughout this playlist we're basically going to go through all of these major products one by one so get started by adding your app let's just follow their steps IOS app bundle ID I'm going to go to my xcode project gonna go to the Target I'm going to go to signing capabilities I'm going to get the bundle identifier right here just going to copy that let's go back to Firebase paste it in app nickname I think this is just for us I'm not going to add a nickname and then App Store ID if your app's already in the App Store you have an app store ID this is basically every app in the app store has an app store ID if you don't have one you can leave this blank for now like I'm gonna do then you can always add these later let's register our app and download the config file so I'm going to click download here it's going to go to my downloads so this is what the config file looks like this is a info.plist file so in every Expo project you already have a plist file so if I go to the info tab this is our basic info.plist that comes with our xcode project and what we're doing now is just adding another info.plist separate of the one in our xcode project but this one is specific for Firebase and as you're going to see in here there's just basically a bunch of IDs basically so that the Firebase SDK knows which project is yours on the server so I'm going to take the downloaded file and just drag and drop it into my project here I'm just going to put it on the left hand let's copy items create groups make sure you're adding it to the Target and finish one thing I'm going to note is that so I've downloaded multiple projects before on this computer and so that's why when it downloaded it has this one at the end because this is the second version of this this is the second file with the same name in my downloads folder so if you have multiple projects this is probably going to happen we do need the name to be exactly Google service Dash info with no extra characters so the this is your case make sure you edit the name here to just be Google service Dash info great we got this in our project let's go back to the documentation click next add the Firebase SDK I can't tell you guys how much I love Swift package manager compared to cocoapods up to this point my channel I've never used a swift package manager before basically it's a super convenient way to get other people's third-party packages into your application and all we need to do is get the GitHub URL and then pull it into our project before we do that though I just want to show you guys that if we go to this website this URL we can actually see the repo for this SDK and so any SDK that is public you'll be able to go to the repo and you can go and you can pull in the https value right here and if it's a swift package manager you can just copy that and then pull it into your app so now that we have the URL let's go back to our xcode project super simple we're going to click file add package and we're going to paste in that package it should come right up now when you pick a package you need to decide which version of the package you want sometimes if it's my own projects or my own packages I would do an exact version and check out a certain Branch or a certain release sometimes you could do a certain Branch so here we can check out the master branch which is the main branch but usually when you're checking out somebody else's package you want to keep it not on the master but on the most recent released brand because we don't really know what Master is it could be the release Branch but it could just be their working Branch we don't know so we're just going to do up to Major version so keeping up to next major version and it looks like it's 9.0.0 to less than 10.0 I'm going to quickly go to the Firebase repo here and look at the releases and usually that up to next major version automatically puts in the most recent release maybe it's just not registering because this is 10.4 but let's actually maybe just use the 10.4 version for now and see how that goes so let's check out a maybe an exam version and we'll do 10.4 we can always change the version later and update as needed add package this should take a second this is probably going to take a couple seconds because the Firebase SDK is massive and there's so many basically sub Frameworks inside of it if you're downloading your own package it's going to be way smaller way faster all right we're gonna get to this screen within the Firebase iOS SDK is all of these products and these products for the most part align with the products in our Firebase console which I'm a little bit of a new tab real quick go back to the Firebase console so basically all of these projects we're looking at now are all of these right authentication database app check are the same thing as here so analytics app check is one and so this is asking us which of these packages within the SDK do we want to include in our app and we don't want to include all of them because we don't want to include the ones that we don't need because these will add to your build times and we generally don't want to include code that is not being used in our projects so as we go through this course we're going to individually add the packages in each video so for right now we're just going to need the ones to set up Firebase so for right now we just want to set up the basic ones that we need so I'm going to look at the documentation here and it says choose the Firebase libraries you want to use make sure to add Firebase analytics and without idfa use this one we're going to use IDF idfa I think that's more common so let's just include the Firebase analytics for now come in here analytic generally if if I see a package that also has a swift version I'm going to include that that's usually just extra super Swifty convenience functions for us so maybe there's some Swift concurrency stuff some async await maybe there's some of these have a combine in them so if you want the combine functions but I think analytics is all we need yeah let's add those let's add that package you're going to see on the left side it is now dependency of our project the Firebase SDK and this little spinner means that it is basically downloading all of the files we'll give that a second while that's happening we're going to come back to our come back to our browser here we did this xcode is resolving next add initialization code so now all we need to do is actually configure Firebase in our project and as you're going to see this is super super simple all we need to do is call Firebase app.configure um and so let's come back into our xcode project here we can see our package dependencies have all loaded a bunch of stuff that probably looks unfamiliar to you but these are just the general packages that are required within Firebase we're gonna go to our app files the main app in our project all right just like the documentation says we are going to import Firebase and then we need to call configure now Swift UI apps do not have an app delegate and for the most part I don't want to use an app delegate there are certain packages within Firebase that are going to require us to use the app delegate to use the app delegate there are certain packages within Firebase that are going to require us to use the app delegate so I'm going to show you how to configure it with or without the app delegate so firstly without super simple before we actually launch the window of our app we can create an initializer for the instance of our app here and we can just call Firebase app dot configure it's that simple and unless you add a little print out here configured Firebase let's build and run our app to a simulator just to make sure we get this printout all right I'm going to run my app real quick got my standard hello world and I could see a bunch of stuff printing out to the console so if you don't see all this stuff then you did something wrong we obviously configured Firebase and then there's a bunch of printouts here debug information our analytics are set up later in this course we're gonna we can enable and disable some of these logs they definitely Firebase definitely even bombards you with logs so there's going to be a point where we want to turn these off but we'll just leave them for now because we don't have much going on configured Firebase this had to do it without an app delegate if we look at their docs they're telling us to do an app delegate which is very simple it's literally this is all the code so here's an app delegate I'm going to copy this let's paste it down here in our app so this is a app delegate so this is the app delete I'm going to highlight this control I to just clean it up and then let's put this on one line so it looks a little bit better and it's and then we can just configure our app here and it did finish launching with options now we just need to make sure that this app here is connected with this app delegate if you're not familiar with an app delegate probably because you are just a swift UI developer in UI kit we use the app delegate to basically host the root of our app there's a bunch of functions that kick off when your app runs like did finish launching there's also functions that run when you close your app and all of those functions are easily accessed through an app delegate this is something I think Apple's definitely moving away from this is why it doesn't come by default and Swift UI apps anymore if you make a UI Kit app the app delegate is baked in to the project so since we're doing an app delegate here we just need to initialize it in our app which they gave us the code for already just going to copy that paste it here and since we're going to use the delegate we no longer need this init so I'm just going to put my print statement down here and then cut this out let's run our app one more time now with an app delegate configured Firebase everything's working I'm going to delete the print statement because we know it's working make sure you won't return true here we always return true this is just running functions before launching the window of your app go back to the documentation we did this let's click next and we are all set that was super super simple that literally you didn't even need to be a developer to connect that it was so easy and let's go back to the console awesome all right that is it guys we are connected to Firebase we have our project connected to the Firebase console and the next couple videos we're going to start going through all the amazing features of Firebase and we're going to start basically the same way you would start building an app with authentication logging users into our app and then we're going to move towards creating user profiles in our database and go from there all right I hope you guys enjoyed this video and I will see you in the next one [Music]
Info
Channel: Swiftful Thinking
Views: 25,868
Rating: undefined out of 5
Keywords: Firebase, Xcode, appdevelopmenttips, iOSdevelopment, mobileappdevelopment, programmingtutorial
Id: sHWX5j6wUjA
Channel Id: undefined
Length: 21min 7sec (1267 seconds)
Published: Mon Mar 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.