iOS
Parse Swift SDK
Quickstart
12 min
install parse sdk on your ios swift project introduction in this section you will learn how to install parse swift 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 choose your installation method swift package manager 1 1 add the parse swift sdk package swift package manager follow this step if you havenât yet installed parse ios sdk newer versions of xcode have the swift package manager built in this is the easiest and best way to install the parse swift sdk on your project and keep it updated currently we only recommend using this method for installing the parse swift sdk under the ( file file ) menu, select ( swift packages swift packages ) and then ( add package dependency add package dependency ) on the ( choose package repository choose package repository ) window, paste the url for the parse swift sdk github website ( https //github com/parse community/parse swift ) and click next next on the ( repository repository ) window, you can select a version version , branch branch or specific commit commit choose the method you prefer and click next next wait for xcode xcode to resolve all parse swift parse swift dependencies and then click next next check if ht package product parseswift parseswift is checked and your target is correctly selected on add to target add to target , then click next next the swift package should appear on the dependencies tree right under your project, showing its version on the right side if you need to update the parseswift parseswift package, right click it under the dependencies tree and choose update package update package the process will automatically update everything for you congratulations! you have now installed the parse swift ios sdk cocoapods 1 1 install the parse swift ios sdk follow this step if you havenât yet installed parse swift 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ââ your podfile will look similar to this now you are going to add parse swift 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 swift 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 parseswift initialize(applicationid "paste your application id here", clientkey "paste your client id here", serverurl url(string "https //parseapi back4app com")!) 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 parseswift your appdelegate swift file should now look like this appdelegate swift 1 import uikit 2 import parseswift 3 4 @main 5 class appdelegate uiresponder, uiapplicationdelegate { 6 7 8 9 func application( application uiapplication, didfinishlaunchingwithoptions launchoptions \[uiapplication launchoptionskey any]?) > bool { 10 // override point for customization after application launch 11 parseswift initialize(applicationid "paste your application id here", clientkey "paste your client id here", serverurl url(string "https //parseapi back4app com")!) 12 return true 13 } 14 15 // mark uiscenesession lifecycle 16 17 func application( application uiapplication, configurationforconnecting connectingscenesession uiscenesession, options uiscene connectionoptions) > uisceneconfiguration { 18 // called when a new scene session is being created 19 // use this method to select a configuration to create the new scene with 20 return uisceneconfiguration(name "default configuration", sessionrole connectingscenesession role) 21 } 22 23 func application( application uiapplication, diddiscardscenesessions scenesessions set\<uiscenesession>) { 24 // called when the user discards a scene session 25 // if any sessions were discarded while the application was not running, this will be called shortly after application\ didfinishlaunchingwithoptions 26 // use this method to release any resources that were specific to the discarded scenes, as they will not return 27 } 28 29 30 } 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 swift appdelegate swift 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 parseswift 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 struct gamescore parseobject { 2 // those are required for object 3 var objectid string? 4 var createdat date? 5 var updatedat date? 6 var acl parseacl? 7	 8 // your own properties 9 var score int = 0 10	 11 // custom initializer 12 init(score int) { 13 self score = score 14 } 15	 16 init(objectid string?) { 17 self objectid = objectid 18 } 19 } 20	 21 func testparseconnection(){ 22 let score = gamescore(score 10) 23 let score2 = gamescore(score 3) 24 score save { result in 25 switch result { 26 case success(let savedscore) 27 assert(savedscore objectid != nil) 28 assert(savedscore createdat != nil) 29 assert(savedscore updatedat != nil) 30 assert(savedscore acl == nil) 31 assert(savedscore score == 10) 32	 33 / to modify, need to make it a var as the value type 34 was initialized as immutable 35 / 36 var changedscore = savedscore 37 changedscore score = 200 38 changedscore save { result in 39 switch result { 40 case success(var savedchangedscore) 41 assert(savedchangedscore score == 200) 42 assert(savedscore objectid == savedchangedscore objectid) 43	 44 / note that savedchangedscore is mutable since it's 45 a var after success 46 / 47 savedchangedscore score = 500 48	 49 case failure(let error) 50 assertionfailure("error saving \\(error)") 51 } 52 } 53 case failure(let error) 54 assertionfailure("error saving \\(error)") 55 } 56 } 57 } 58 } build your app in a device or simulator ( command command + r r ) wait until the main screen appears login at back4app website https //www back4app com/ find your app and click on dashboard dashboard click on core core go to browser browser if everything works properly, you should find a class named gamescore gamescore and the saved objects in it 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