⭐️ ParseSwift was highlighted in issue #560 of iOS Dev Weekly and discussed in episode 5 of Swift Package Index Twitter Spaces
A pure Swift library that gives you access to the powerful Parse Server backend. See why ParseSwiftOG is better than all of the other Parse SDK's by reviewing the feature comparison tables.
The ParseSwiftOG SDK is not a port of the Parse-SDK-iOS-OSX SDK and though some of it may feel familiar, it is not backwards compatible and is designed using protocol oriented programming (POP) and value types instead of OOP and reference types. You can learn more about POP by watching Protocol-Oriented Programming in Swift or Protocol and Value Oriented Programming in UIKit Apps videos from previous WWDC's. For more details about ParseSwiftOG, visit the api documentation.
ℹ️ Why Choose ParseSwiftOG Over parse-community/Parse-Swift?
This repo is maintained by Corey E. Baker, 1 of 2 of the original developers of ParseSwift. Corey was responsible for the direction and development of all parse-community releases of ParseSwift from 1.0.0 to 4.14.2. ParseSwiftOG has the most up-to-date features and bug fixes to develop client and server-side applications. It is the most flexible Parse Client SDK to date, can be used to write Cloud Code, and is developed with zero dependencies. This repo is aligned with the original core principals of a swifty framework. Star, watch, and submit questions, issues, and pull requests to NetReconLab ParseSwiftOG instead of the parse-community ParseSwift to support it's development. Learn how to seemlessly migrate your apps from parse-community to ParseSwiftOG by reading the discussion. For more details about why ParseSwiftOG exists, see the discussion. If you benefit from ParseSwift and would like to show monetary support, feel free to:
Developers who dedicate their time and effort are who make this repo possible!
- Why use ParseSwiftOG from NetReconLab?
- Contributors
- Example Apps and Frameworks
- Test Drive Parse-Swift
- Installation
- Usage Guide
- LiveQuery
- Migrating from Older Versions and SDKs
Below is a list of apps and frameworks that use ParseSwiftOG to help developers take advantage of the framework:
- ParseServerSwift - Write Parse Cloud Code in Swift using ParseSwiftOG
- ParseServerAnyAnalytics - Analytics adapter to connect Parse Server analytics to any 3rd party analytics tool
- CarekitSampe-ParseCareKit - An example application of CareKit's OCKSample synchronizing CareKit data to the Cloud via ParseCareKit
- ParseCareKit - Synchronize CareKit 2.1+ data with a parse-server using ParseSwiftOG
- SnapCat - SnapCat is a social media application for posting pictures, comments, and finding friends. SnapCat is designed using SwiftUI and the ParseSwiftOG SDK
- ParseMigrateKeychain - A sample app that demonstrates how to migrate an app written with the Parse Objective-C SDK to the ParseSwiftOG SDK. Learn more, see the discussion.
To learn how to use or experiment with ParseSwiftOG, you can run and edit the ParseSwift.playground. You can use the parse-server in this repo which has docker compose files (docker-compose up
gives you a working server) configured to connect with the playground files, has Parse Dashboard, and can be used with MongoDB or PostgreSQL. You can also configure the Swift Playgrounds to work with your own Parse Server by editing the configuation in Common.swift. To learn more, see this discussion or CONTRIBUTING.md.
You can use The Swift Package Manager (SPM) to install ParseSwiftOG by adding the following description to your Package.swift
file:
// swift-tools-version:5.5.2
import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/netreconlab/Parse-Swift", .upToNextMajor(from: "5.7.0")),
]
)
Then run swift build
.
You can also install using SPM in your Xcode project by going to
"Project->NameOfYourProject->Swift Packages" and placing https://github.com/netreconlab/Parse-Swift.git
in the
search field.
Add the following line to your Podfile:
pod 'ParseSwiftOG'
To link to the latest updates on the main branch, add the following line to your Podfile:
pod 'ParseSwiftOG', :git => 'https://github.com/netreconlab/Parse-Swift.git', :branch => 'main'
In your projects, use:
import ParseSwiftOG
After installing ParseSwiftOG, to use it first import ParseSwift
in your AppDelegate.swift and then add the following code in your application:didFinishLaunchingWithOptions:
method:
try await ParseSwift.initialize(applicationId: "xxxxxxxxxx", clientKey: "xxxxxxxxxx", serverURL: URL(string: "https://example.com")!)
Please checkout the Swift Playground for more usage information.
Query
is one of the key concepts on the Parse Platform. It allows you to retrieve ParseObject
s by specifying some conditions, making it easy to build apps such as a dashboard, a todo list or even some strategy games. However, Query
is based on a pull model, which is not suitable for apps that need real-time support.
Suppose you are building an app that allows multiple users to edit the same file at the same time. Query
would not be an ideal tool since you can not know when to query from the server to get the updates.
To solve this problem, we introduce Parse LiveQuery. This tool allows you to subscribe to a Query
you are interested in. Once subscribed, the server will notify clients whenever a ParseObject
that matches the Query
is created or updated, in real-time.
Parse LiveQuery contains two parts, the LiveQuery server and the LiveQuery clients (this SDK). In order to use live queries, you need to at least setup the server.
The easiest way to setup the LiveQuery server is to make it run with the Open Source Parse Server.
The LiveQuery client interface is based around the concept of Subscription
s. You can register any Query
for live updates from the associated live query server and use the query as a view model for a SwiftUI view by simply using the subscribe
property of a query: https://github.com/netreconlab/Parse-Swift/blob/0c17c781a211299f324753fa9bcbb6845c22fad2/ParseSwift.playground/Pages/19%20-%20SwiftUI%20-%20LiveQuery.xcplaygroundpage/Contents.swift#L66-L125
or by calling the subscribe(_ client: ParseLiveQuery)
method of a query. If you want to customize your view model more you can subclass Subscription
or add the subscription to your own view model. You can test out LiveQuery subscriptions in Swift Playgrounds.
You can also use asynchronous call backs to subscribe to a LiveQuery:
let myQuery = Message.query("from" == "parse")
do {
let subscription = try await myQuery.subscribeCallback()
} catch {
print("Error subscribing...")
}
or by calling the subscribeCallback(_ client: ParseLiveQuery)
method of a query.
Where Message
is a ParseObject.
Once you've subscribed to a query, you can handle
events on them, like so:
subscription.handleSubscribe { subscribedQuery, isNew in
//Handle the subscription however you like.
if isNew {
print("Successfully subscribed to new query \(subscribedQuery)")
} else {
print("Successfully updated subscription to new query \(subscribedQuery)")
}
}
You can handle any event for LiveQuery docs:
subscription.handleEvent { _, event in
// Called whenever an object was created
switch event {
case .entered(let object):
print("Entered: \(object)")
case .left(let object):
print("Left: \(object)")
case .created(let object):
print("Created: \(object)")
case .updated(let object):
print("Updated: \(object)")
case .deleted(let object):
print("Deleted: \(object)")
}
}
Similiarly, you can unsubscribe and register to be notified when it occurs:
subscription.handleUnsubscribe { query in
print("Unsubscribed from \(query)")
}
//: To unsubscribe from your query.
do {
try await query.unsubscribe()
} catch {
print(error)
}
Handling errors is and other events is similar, take a look at the Subscription
class for more information. You can test out LiveQuery subscriptions in Swift Playgrounds.
You are not limited to a single Live Query Client - you can create multiple instances of ParseLiveQuery
, use certificate authentication and pinning, receive metrics about each client connection, connect to individual server URLs, and more.
- See the discussion to learn how to migrate from ParseSwiftOG 4.15.0+ to 5.1.1+
- See the discussion to learn how to migrate from parse-community/Parse-Swift
- See the discussion to learn how to migrate from Parse-SDK-iOS-OSX