在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):parse-community/Parse-Swift开源软件地址(OpenSource Url):https://github.com/parse-community/Parse-Swift开源编程语言(OpenSource Language):Swift 99.6%开源软件介绍(OpenSource Introduction):iOS · macOS · watchOS · tvOS · Linux · Android · WindowsA 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 ( InstallationSwift Package ManagerYou can use The Swift Package Manager (SPM) to install ParseSwift by adding the following description to your // 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 You can also install using SPM in your Xcode project by going to
"Project->NameOfYourProject->Swift Packages" and placing CocoaPodsAdd the following line to your Podfile: pod 'ParseSwift' Run CarthageAdd the following line to your Cartfile:
Run Usage GuideAfter installing ParseSwift, to use it first ParseSwift.initialize(applicationId: "xxxxxxxxxx", clientKey: "xxxxxxxxxx", serverURL: URL(string: "https://example.com")!) Please checkout the Swift Playground for more usage information. LiveQuery
Suppose you are building an app that allows multiple users to edit the same file at the same time. To solve this problem, we introduce Parse LiveQuery. This tool allows you to subscribe to a Setup ServerParse 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 ClientSwiftUI View Models Using CombineThe LiveQuery client interface is based around the concept of 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 Traditional CallbacksYou 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 Where Once you've subscribed to a query, you can 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 Advanced UsageYou are not limited to a single Live Query Client - you can create multiple instances of |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论