• Stars
    star
    299
  • Rank 136,492 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Swift SDK for Parse Platform (iOS, macOS, watchOS, tvOS, Linux, Android, Windows)

parse-repository-header-sdk-swift

iOS 路 macOS 路 watchOS 路 tvOS 路 Linux 路 Android 路 Windows


Build Status CI Build Status Release Coverage Carthage Pod

Swift Versions Platforms

Backers on Open Collective Sponsors on Open Collective License Forum Twitter


A pure Swift library that gives you access to the powerful Parse Server backend from your Swift applications.

For more information about the Parse Platform and its features, see the public documentation. The ParseSwift 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 ParseSwift, visit the api documentation.

To learn how to use or experiment with ParseSwift, 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, check out CONTRIBUTING.md.


Installation

Swift Package Manager

You can use The Swift Package Manager (SPM) to install ParseSwift by adding the following description to your Package.swift file:

// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        .package(url: "https://github.com/parse-community/Parse-Swift", .upToNextMajor(from: "4.0.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/parse-community/Parse-Swift.git in the search field.

CocoaPods

Add the following line to your Podfile:

pod 'ParseSwift'

Run pod install, and you should now have the latest version from the main branch.

Carthage

Add the following line to your Cartfile:

github "parse-community/Parse-Swift"

Run carthage update, and you should now have the latest version of ParseSwift SDK in your Carthage folder.

Usage Guide

After installing ParseSwift, to use it first import ParseSwift in your AppDelegate.swift and then add the following code in your application:didFinishLaunchingWithOptions: method:

ParseSwift.initialize(applicationId: "xxxxxxxxxx", clientKey: "xxxxxxxxxx", serverURL: URL(string: "https://example.com")!)

Please checkout the Swift Playground for more usage information.

LiveQuery

Query is one of the key concepts on the Parse Platform. It allows you to retrieve ParseObjects 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.

Setup Server

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.

Use Client

SwiftUI View Models Using Combine

The LiveQuery client interface is based around the concept of Subscriptions. 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:

let myQuery = GameScore.query("points" > 9)

struct ContentView: View {

    //: A LiveQuery subscription can be used as a view model in SwiftUI
    @StateObject var subscription = myQuery.subscribe!
    
    var body: some View {
        VStack {

            if subscription.subscribed != nil {
                Text("Subscribed to query!")
            } else if subscription.unsubscribed != nil {
                Text("Unsubscribed from query!")
            } else if let event = subscription.event {

                //: This is how you register to receive notificaitons of events related to your LiveQuery.
                switch event.event {

                case .entered(let object):
                    Text("Entered with points: \(object.points)")
                case .left(let object):
                    Text("Left with points: \(object.points)")
                case .created(let object):
                    Text("Created with points: \(object.points)")
                case .updated(let object):
                    Text("Updated with points: \(object.points)")
                case .deleted(let object):
                    Text("Deleted with points: \(object.points)")
                }
            } else {
                Text("Not subscribed to a query")
            }

            Spacer()

            Text("Update GameScore in Parse Dashboard to see changes here")

            Button(action: {
                try? query.unsubscribe()
            }, label: {
                Text("Unsubscribe")
                    .font(.headline)
                    .background(Color.red)
                    .foregroundColor(.white)
                    .padding()
                    .cornerRadius(20.0)
                    .frame(width: 300, height: 50)
            })
        }
    }
}

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.

Traditional Callbacks

You can also use asynchronous call backs to subscribe to a LiveQuery:

let myQuery = Message.query("from" == "parse")
guard let subscription = myQuery.subscribeCallback else {
    print("Error subscribing...")
    return
}

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 listed in the LiveQuery spec:

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 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.

Advanced Usage

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.

Migration from Parse ObjC SDK

See the Migration Guide to help you migrate from the Parse ObjC SDK.

More Repositories

1

parse-server

Parse Server for Node.js / Express
JavaScript
20,674
star
2

parse-dashboard

A dashboard for managing Parse Server
JavaScript
3,728
star
3

Parse-SDK-iOS-OSX

The Apple SDK for Parse Platform (iOS, macOS, watchOS, tvOS)
Objective-C
2,803
star
4

parse-server-example

Example of Parse Server using the express framework.
JavaScript
1,879
star
5

Parse-SDK-Android

The Android SDK for Parse Platform
Java
1,878
star
6

Parse-SDK-JS

The JavaScript SDK for Parse Platform
JavaScript
1,311
star
7

ParseReact

Seamlessly bring Parse data into your React applications.
JavaScript
1,295
star
8

ParseUI-iOS

A collection of a handy user interface components to be used with the Parse iOS SDK.
Objective-C
935
star
9

parse-php-sdk

The PHP SDK for Parse Platform
PHP
812
star
10

ParseUI-Android

ParseUI contains user interface libraries for building apps with the Parse Android SDK.
Java
592
star
11

Parse-SDK-Flutter

The Dart/Flutter SDK for Parse Platform
Dart
568
star
12

Parse-SDK-dotNET

Parse SDK for .NET, Xamarin, Unity.
C#
321
star
13

docs

Parse Platform docs
SCSS
314
star
14

parse-embedded-sdks

The Embedded SDKs for the Parse Platform
C
246
star
15

ParseLiveQuery-iOS-OSX

Parse LiveQuery Client for iOS/OS X.
Swift
192
star
16

parse-cli

Go
118
star
17

ParseFacebookUtils-iOS

A set of utilities to integrate Facebook with the Parse iOS/tvOS SDK.
Objective-C
92
star
18

parse-server-push-adapter

A push notification adapter for Parse Server
JavaScript
84
star
19

parse-server-simple-mailgun-adapter

Used to send Parse Server password reset and email verification emails though Mailgun
JavaScript
84
star
20

ParseLiveQuery-Android

Parse LiveQuery client for Android.
Java
84
star
21

parse-server-s3-adapter

AWS S3 file storage adapter for Parse Server
JavaScript
76
star
22

parse-react

[EXPERIMENTAL] React, React Native, and React with SSR (e.g. Next.js) packages to interact with Parse Server backend
TypeScript
70
star
23

Parse-SDK-Arduino

The Arduino SDK for the Parse Platform
C++
67
star
24

ParseFacebookUtils-Android

A utility library to authenticate ParseUsers with the Facebook SDK
Java
53
star
25

ParseTwitterUtils-iOS

A set of utilities to integrate Twitter with the Parse iOS SDK.
Objective-C
46
star
26

parse-server-fs-adapter

parse-server file system storage adapter
JavaScript
42
star
27

ParseInterceptors-Android

Parse Network Interceptor Debugging
Java
37
star
28

ParseTwitterUtils-Android

A utility library to authenticate ParseUsers with Twitter
Java
36
star
29

parse-blockchain

Blockchain (Ethereum) dApps development made easy with Parse Server (alpha)
TypeScript
36
star
30

parse-facebook-user-session

A Cloud Code module to facilitate logging into an express website with Facebook.
JavaScript
36
star
31

parse-server-gcs-adapter

parse-server adapter for Google Cloud Storage
JavaScript
29
star
32

parse-server-api-mail-adapter

API Mail Adapter for Parse Server
JavaScript
25
star
33

benchmark

Parse Server Continuous Benchmark
JavaScript
24
star
34

xctoolchain-archive

Common configuration files and scripts that are used to build our SDKs with Xcode.
Ruby
22
star
35

blog

Parse Community Blog
SCSS
18
star
36

parse-server-sqs-mq-adapter

Spread work queue accross cluster of parse servers using SQS
JavaScript
17
star
37

parse-community.github.io

Parse Platform GitHub Pages
SCSS
10
star
38

relay-examples

Parse-Server GraphQL Relay Todo
JavaScript
10
star
39

Governance

Details about the leadership & decision making process for the Parse Community
10
star
40

parse-server-conformance-tests

Conformance tests for parse-server adapters
JavaScript
7
star
41

parse-community-peril

Peril for the parse-community
TypeScript
6
star
42

.github

Default community health files for the Parse Community
4
star
43

release-automation-playground

A playground repo to experiment with release automation.
2
star
44

docs-tutorial-todoapp

A tutorial for developing a ToDo app with Parse Platform
1
star