So now that you set up a free Parse server on Heroku using my previous guide you might be wondering how to start using it in your iOS project. Checking the main Parse documentation shows a bunch of Objective-C, which isn’t helpful if you’re using Swift 3.
Here are the steps I gathered from perusing the web and some testing:
- Install Parse libraries (SDK/Framework).
- I prefer cocoapods to maintain to a single standard and since so many other frameworks use it.
- Create ‘Podfile‘ file in the xcode project folder with the following contents:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '10.0' use_frameworks! target 'PROJECT_NAME' do pod 'Parse' end
- Run ‘pod install‘ in terminal in the same directory as the Podfile.
- Connect your Swift 3 app to Parse server.
- Import Parse framework by adding ‘import Parse‘ at the top of ‘AppDelegate.swift‘ file.
- In ‘AppDelegate.swift‘ under function ‘application(… didFinishLaunchingWithOptions …)‘ add the following code:
let configuration = ParseClientConfiguration { $0.applicationId = "YOUR_PARSE_APP_ID" $0.clientKey = "YOUR_PARSE_CLIENT_KEY" $0.server = "https://PARSE_SERVER_NAME.herokuapp.com/parse" } Parse.initialize(with: configuration)
- Test Parse server connection.
- Import Parse framework by adding ‘import Parse‘ at the top of ‘ViewController.swift‘ file.
- In ‘ViewController.swift‘ file, add the following code under function ‘ViewDidLoad‘:
let testObj = PFObject(className: "testObj") testObj["foo"] = "bar" testObj.saveInBackground()
- You should see the new object in your Parse Dashboard.
Notes/Troubleshooting
If XCode can’t find the Parse module with the import command after you open the new .xcworkspace file, try the following:
- Press Command+Option+Shift+K and then Run your app.
- Or from the menu -> Product, press Option on your keyboard and you’ll see Clean Build Folder.