iOS
Install Parse SDK (Swift)
18 min
install parse sdk on your ios swift project introduction in this section you will learn how to install parse ios sdk into your xcode project in this tutorial we will use a basic app created in swift with xcode 12 and ios 14 at any time, you can access the complete project built with this tutorial at our github repository prerequisites to complete this tutorial, you need an app created at back4app note follow the new parse app tutorial to learn how to create an app at back4app xcode basic ios app note if you don’t have a basic app created you can open xcode and hit file > new > project > ios then select app after you create your basic app you are ready to follow this guide 1 install sdk follow this step if you haven’t yet installed parse ios sdk xcode can use cocoapods as dependency manager for swift and objective c cocoa projects you can refer to cocoapods getting started guide for additional details to install cocoapods, open your terminal, copy the following code snippet and paste it in to your terminal and hit return cocoapods should install automatically after you enter your password if there’s a problem you may need to upgrade your local version of ruby next open up the xcode project folder and open a terminal window in that folder now you are going to create a podfile copy the following code snippet and paste it in to your terminal and hit return if your folder now shows your podfile you did it correctly be careful, if you don’t see the podfile make sure your terminal is actually inside the project folder next open your podfile with xcode or any text editor and under each target add “pod ‘parse’” now you are going to add parse to your project make sure your terminal is opened to your project folder copy the following code snippet and paste it in to your terminal and hit return cocoapods will rebuild the project as a workspace and your project will now look like this if you have already opened your xcode project close it from now on you’ll open the workspace file instead of the project file double click on the workspace file to open it congratulations! you have now installed the parse ios sdk 2 connect your parse app open your project’s appdelegate swift file to set up the app’s credentials parse ios sdk uses these settings to connect to the back4app servers at the top of the file you should see a function called ‘didfinishlaunchingwithoptions’ paste the following code snippet inside this function, and make sure it is above the line that says ‘return true’ appdelegate swift 1 let configuration = parseclientconfiguration { 2 $0 applicationid = "paste your application id here" 3 $0 clientkey = "paste your client id here" 4 $0 server = "https //parseapi back4app com" 5 } 6 parse initialize(with configuration) at the top of your appdelegate swift file make sure to include parse as a module by including the follwing code snippet right below ‘import uikit’ appdelegate swift 1 import parse your appdelegate swift file should now look like this be careful , if xcode tells you there is no such module ‘parse’ there’s an easy solution in xcode open ‘target > build settings > search paths > framework search paths’ and then add two values ‘$(project dir)’ and ‘$(inherited)’ xcode will now be able to find your parse module go to your app dashboard at back4app website navigate to app’s settings click on features features > core settings core settings block> server server return to your appdelegate m appdelegate m file and paste your applicationid applicationid and clientkey clientkey see more at our new parse app guide 3 test your connection open your viewcontroller swift file at the top of the file make sure to include parse as a module by including the follwing code snippet right below ‘import uikit’ viewcontroller swift 1 import parse inside the function called ‘viewdidload’ add a snippet of code below the code that configures parse viewcontroller swift 1 testparseconnection() then add a function below viewdidload() method viewcontroller swift 1 func testparseconnection(){ 2 let myobj = pfobject(classname "firstclass") 3 myobj\["message"] = "hey ! first message from swift parse is now connected" 4 myobj saveinbackground { (success, error) in 5 if(success){ 6 print("you are connected!") 7 }else{ 8 print("an error has occurred!") 9 } 10 } 11 } 12 } your finished viewcontroller swift file should look like this build your app in a device or simulator ( command command + r r ) 2\ wait until the main screen appears 3\ login at back4app website 4\ find your app and click on dashboard dashboard 5\ click on core core 6\ go to browser browser if everything works properly, you should find a class named firstclass firstclass as follows next steps at this point, you have learned how to get started with ios apps you are now ready to explore parse server core features https //www back4app com/product/parse server and back4app add ons https //www back4app com/product/addons learn more by walking around our ios tutorials or check parse open source documentation for ios sdk