Skip to content

Commit f455830

Browse files
authored
feat: Update to ParseSwift 5.0.1 (#185)
* feat: Update to ParseSwift 5.0.0 * Update proj files * remove ACL from init * test latest ParseSwift * update * latest * add back ACL to init * update to latest ParseSwift
1 parent 545e4ac commit f455830

File tree

11 files changed

+227
-233
lines changed

11 files changed

+227
-233
lines changed

Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"repositoryURL": "https://github.com/netreconlab/Parse-Swift.git",
2525
"state": {
2626
"branch": null,
27-
"revision": "fd285005023271e615062cfad1d92261ee55fe4b",
28-
"version": "5.0.0-beta.9"
27+
"revision": "ed55608e5d2486a5d9bca61f553313d7b21bbbb2",
28+
"version": "5.0.1"
2929
}
3030
}
3131
]

Package.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.5.2
22

33
import PackageDescription
44

@@ -13,7 +13,8 @@ let package = Package(
1313
dependencies: [
1414
.package(url: "https://github.com/cbaker6/CareKit.git",
1515
.upToNextMajor(from: "2.1.8")),
16-
.package(url: "https://github.com/netreconlab/Parse-Swift.git", .exact("5.0.0-beta.9"))
16+
.package(url: "https://github.com/netreconlab/Parse-Swift.git",
17+
.upToNextMajor(from: "5.0.1"))
1718
],
1819
targets: [
1920
.target(

ParseCareKit.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1158,8 +1158,8 @@
11581158
isa = XCRemoteSwiftPackageReference;
11591159
repositoryURL = "https://github.com/netreconlab/Parse-Swift.git";
11601160
requirement = {
1161-
kind = exactVersion;
1162-
version = "5.0.0-beta.9";
1161+
kind = upToNextMajorVersion;
1162+
minimumVersion = 5.0.1;
11631163
};
11641164
};
11651165
70DF63DA29719D6E002FA5C5 /* XCRemoteSwiftPackageReference "CareKit" */ = {

Sources/ParseCareKit/Objects/PCKClock.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ struct PCKClock: ParseObject {
114114
}
115115

116116
func setupACLWithRoles() async throws -> Self {
117-
guard let currentUser = PCKUser.current else {
118-
throw ParseCareKitError.errorString("No user is signed in")
119-
}
120-
117+
let currentUser = try await PCKUser.current()
121118
let writeRole = try await setupWriteRole(currentUser)
122119
let readRole = try await setupReadRole(currentUser)
123120
let writeRoleName = try PCKWriteRole.roleName(owner: currentUser)

Sources/ParseCareKit/Objects/PCKOutcome.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
437437
return query
438438
}
439439

440-
func findOutcomes() throws -> [PCKOutcome] {
440+
func findOutcomes() async throws -> [PCKOutcome] {
441441
let query = Self.queryNotDeleted()
442-
return try query.find()
442+
return try await query.find()
443443
}
444444

445445
public func findOutcomesInBackground(completion: @escaping([PCKOutcome]?, Error?) -> Void) {

Sources/ParseCareKit/PCKUtility.swift

+14-13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import ParseSwift
11+
import os.log
1112

1213
// swiftlint:disable line_length
1314

@@ -47,7 +48,7 @@ public class PCKUtility {
4748
public class func setupServer(fileName: String = "ParseCareKit",
4849
authentication: ((URLAuthenticationChallenge,
4950
(URLSession.AuthChallengeDisposition,
50-
URLCredential?) -> Void) -> Void)? = nil) throws {
51+
URLCredential?) -> Void) -> Void)? = nil) async throws {
5152
var plistConfiguration: [String: AnyObject]
5253
var clientKey: String?
5354
var liveQueryURL: URL?
@@ -81,15 +82,15 @@ public class PCKUtility {
8182
deleteKeychainIfNeeded = deleteKeychain
8283
}
8384

84-
try ParseSwift.initialize(applicationId: appID,
85-
clientKey: clientKey,
86-
serverURL: serverURL,
87-
liveQueryServerURL: liveQueryURL,
88-
requiringCustomObjectIds: true,
89-
usingTransactions: useTransactions,
90-
usingPostForQuery: true,
91-
deletingKeychainIfNeeded: deleteKeychainIfNeeded,
92-
authentication: authentication)
85+
try await ParseSwift.initialize(applicationId: appID,
86+
clientKey: clientKey,
87+
serverURL: serverURL,
88+
liveQueryServerURL: liveQueryURL,
89+
requiringCustomObjectIds: true,
90+
usingTransactions: useTransactions,
91+
usingPostForQuery: true,
92+
deletingKeychainIfNeeded: deleteKeychainIfNeeded,
93+
authentication: authentication)
9394
}
9495

9596
/**
@@ -100,7 +101,7 @@ public class PCKUtility {
100101
- SynchronizeKeychain - (Boolean) Whether or not to synchronize the Keychain across devices.
101102
- parameter fileName: Name of **.plist** file that contains config. Defaults to "ParseCareKit".
102103
*/
103-
public class func setAccessGroup(fileName: String = "ParseCareKit") throws {
104+
public class func setAccessGroup(fileName: String = "ParseCareKit") async throws {
104105
var plistConfiguration: [String: AnyObject]
105106
var accessGroup: String?
106107
var synchronizeKeychain = false
@@ -119,8 +120,8 @@ public class PCKUtility {
119120
synchronizeKeychain = synchronizeKeychainAcrossDevices
120121
}
121122

122-
try ParseSwift.setAccessGroup(accessGroup,
123-
synchronizeAcrossDevices: synchronizeKeychain)
123+
try await ParseSwift.setAccessGroup(accessGroup,
124+
synchronizeAcrossDevices: synchronizeKeychain)
124125
}
125126

126127
/// Get the current Parse Encoder with custom date strategy.

Sources/ParseCareKit/ParseRemote.swift

+93-79
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,24 @@ public class ParseRemote: OCKRemoteSynchronizable {
6161
Requires `ParseLiveQuery` server to be setup.
6262
- defaultACL: The default access control list for which users can access or modify `ParseCareKit`
6363
objects. If no `defaultACL` is provided, the default is set to read/write for the user who created the data with
64-
no public read/write access. This `defaultACL` is not the same as `ParseACL.defaultACL`. If you want the
65-
the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`, you need to provide
66-
`ParseACL.defaultACL`.
64+
no public read/write access.
65+
- important: This `defaultACL` is not the same as `ParseACL.defaultACL`.
66+
- note: If you want the the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`,
67+
you need to provide `ParseACL.defaultACL`.
6768
*/
6869
public init(uuid: UUID,
6970
auto: Bool,
7071
subscribeToServerUpdates: Bool,
71-
defaultACL: ParseACL? = nil) throws {
72+
defaultACL: ParseACL? = nil) async throws {
7273
self.pckStoreClassesToSynchronize = try PCKStoreClass.patient.getConcrete()
7374
self.customClassesToSynchronize = nil
7475
self.uuid = uuid
7576
self.clockQuery = PCKClock.query(ClockKey.uuid == uuid)
7677
self.automaticallySynchronizes = auto
7778
self.subscribeToServerUpdates = subscribeToServerUpdates
78-
if let currentUser = PCKUser.current {
79-
Self.setDefaultACL(defaultACL, for: currentUser)
80-
subscribeToClock()
79+
if let currentUser = try? await PCKUser.current() {
80+
try Self.setDefaultACL(defaultACL, for: currentUser)
81+
await subscribeToClock()
8182
}
8283
}
8384

@@ -91,19 +92,20 @@ public class ParseRemote: OCKRemoteSynchronizable {
9192
Requires `ParseLiveQuery` server to be setup.
9293
- defaultACL: The default access control list for which users can access or modify `ParseCareKit`
9394
objects. If no `defaultACL` is provided, the default is set to read/write for the user who created the data with
94-
no public read/write access. This `defaultACL` is not the same as `ParseACL.defaultACL`. If you want the
95-
the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`, you need to provide
96-
`ParseACL.defaultACL`.
95+
no public read/write access.
96+
- important: This `defaultACL` is not the same as `ParseACL.defaultACL`.
97+
- note: If you want the the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`,
98+
you need to provide `ParseACL.defaultACL`.
9799
*/
98100
convenience public init(uuid: UUID,
99101
auto: Bool,
100102
replacePCKStoreClasses: [PCKStoreClass: PCKSynchronizable],
101103
subscribeToServerUpdates: Bool,
102-
defaultACL: ParseACL? = nil) throws {
103-
try self.init(uuid: uuid,
104-
auto: auto,
105-
subscribeToServerUpdates: subscribeToServerUpdates,
106-
defaultACL: defaultACL)
104+
defaultACL: ParseACL? = nil) async throws {
105+
try await self.init(uuid: uuid,
106+
auto: auto,
107+
subscribeToServerUpdates: subscribeToServerUpdates,
108+
defaultACL: defaultACL)
107109
try self.pckStoreClassesToSynchronize = PCKStoreClass
108110
.patient.replaceRemoteConcreteClasses(replacePCKStoreClasses)
109111
self.customClassesToSynchronize = nil
@@ -121,20 +123,21 @@ public class ParseRemote: OCKRemoteSynchronizable {
121123
Requires `ParseLiveQuery` server to be setup.
122124
- defaultACL: The default access control list for which users can access or modify `ParseCareKit`
123125
objects. If no `defaultACL` is provided, the default is set to read/write for the user who created the data with
124-
no public read/write access. This `defaultACL` is not the same as `ParseACL.defaultACL`. If you want the
125-
the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`, you need to provide
126-
`ParseACL.defaultACL`.
126+
no public read/write access.
127+
- important: This `defaultACL` is not the same as `ParseACL.defaultACL`.
128+
- note: If you want the the `ParseCareKit` `defaultACL` to match the `ParseACL.defaultACL`,
129+
you need to provide `ParseACL.defaultACL`.
127130
*/
128131
convenience public init(uuid: UUID,
129132
auto: Bool,
130133
replacePCKStoreClasses: [PCKStoreClass: PCKSynchronizable]? = nil,
131134
customClasses: [String: PCKSynchronizable],
132135
subscribeToServerUpdates: Bool,
133-
defaultACL: ParseACL? = nil) throws {
134-
try self.init(uuid: uuid,
135-
auto: auto,
136-
subscribeToServerUpdates: subscribeToServerUpdates,
137-
defaultACL: defaultACL)
136+
defaultACL: ParseACL? = nil) async throws {
137+
try await self.init(uuid: uuid,
138+
auto: auto,
139+
subscribeToServerUpdates: subscribeToServerUpdates,
140+
defaultACL: defaultACL)
138141
if replacePCKStoreClasses != nil {
139142
self.pckStoreClassesToSynchronize = try PCKStoreClass
140143
.patient.replaceRemoteConcreteClasses(replacePCKStoreClasses!)
@@ -145,27 +148,29 @@ public class ParseRemote: OCKRemoteSynchronizable {
145148
}
146149

147150
deinit {
148-
do {
149-
try clockQuery.unsubscribe()
150-
if #available(iOS 14.0, watchOS 7.0, *) {
151-
Logger.deinitializer.error("Unsubscribed from clock query")
152-
} else {
153-
os_log("Unsubscribed from clock query",
154-
log: .deinitializer,
155-
type: .error)
156-
}
157-
} catch {
158-
if #available(iOS 14.0, watchOS 7.0, *) {
159-
Logger.deinitializer.error("Couldn't unsubscribe from clock query")
160-
} else {
161-
os_log("Couldn't unsubscribe from clock query",
162-
log: .deinitializer,
163-
type: .error)
151+
Task {
152+
do {
153+
try await clockQuery.unsubscribe()
154+
if #available(iOS 14.0, watchOS 7.0, *) {
155+
Logger.deinitializer.error("Unsubscribed from clock query")
156+
} else {
157+
os_log("Unsubscribed from clock query",
158+
log: .deinitializer,
159+
type: .error)
160+
}
161+
} catch {
162+
if #available(iOS 14.0, watchOS 7.0, *) {
163+
Logger.deinitializer.error("Couldn't unsubscribe from clock query")
164+
} else {
165+
os_log("Couldn't unsubscribe from clock query",
166+
log: .deinitializer,
167+
type: .error)
168+
}
164169
}
165170
}
166171
}
167172

168-
class func setDefaultACL(_ defaultACL: ParseACL?, for user: PCKUser) {
173+
class func setDefaultACL(_ defaultACL: ParseACL?, for user: PCKUser) throws {
169174
let acl: ParseACL!
170175
if let defaultACL = defaultACL {
171176
acl = defaultACL
@@ -206,19 +211,35 @@ public class ParseRemote: OCKRemoteSynchronizable {
206211
type: .error,
207212
error.localizedDescription)
208213
}
214+
throw error
209215
}
210216
}
211217

212-
func subscribeToClock() {
213-
DispatchQueue.main.async {
214-
215-
guard PCKUser.current != nil,
216-
self.subscribeToServerUpdates == true,
217-
self.clockSubscription == nil else {
218+
@MainActor
219+
func subscribeToClock() async {
220+
do {
221+
_ = try await PCKUser.current()
222+
guard self.subscribeToServerUpdates == true,
223+
self.clockSubscription == nil else {
218224
return
219225
}
220226

221-
guard let subscription = self.clockQuery.subscribeCallback else {
227+
do {
228+
let subscription = try await self.clockQuery.subscribeCallback()
229+
self.clockSubscription = subscription
230+
self.clockSubscription?.handleEvent { (_, _) in
231+
self.parseDelegate?.didRequestSynchronization(self)
232+
if #available(iOS 14.0, watchOS 7.0, *) {
233+
Logger
234+
.clockSubscription
235+
.log("Parse subscription is notifying that there are updates on the server")
236+
} else {
237+
os_log("Parse subscription is notifying that there are updates on the server",
238+
log: .clockSubscription,
239+
type: .info)
240+
}
241+
}
242+
} catch {
222243
if #available(iOS 14.0, watchOS 7.0, *) {
223244
Logger.clockSubscription.error("Couldn't subscribe to clock query")
224245
} else {
@@ -228,32 +249,22 @@ public class ParseRemote: OCKRemoteSynchronizable {
228249
}
229250
return
230251
}
231-
self.clockSubscription = subscription
232-
self.clockSubscription?.handleEvent { (_, _) in
233-
self.parseDelegate?.didRequestSynchronization(self)
234-
if #available(iOS 14.0, watchOS 7.0, *) {
235-
Logger
236-
.clockSubscription
237-
.log("Parse subscription is notifying that there are updates on the server")
238-
} else {
239-
os_log("Parse subscription is notifying that there are updates on the server",
240-
log: .clockSubscription,
241-
type: .info)
242-
}
243-
}
252+
} catch {
253+
return
244254
}
245255
}
246256

247257
public func pullRevisions(since knowledgeVector: OCKRevisionRecord.KnowledgeVector,
248258
mergeRevision: @escaping (OCKRevisionRecord) -> Void,
249259
completion: @escaping (Error?) -> Void) {
250260

251-
guard PCKUser.current != nil else {
252-
completion(ParseCareKitError.userNotLoggedIn)
253-
return
254-
}
255-
256261
Task {
262+
do {
263+
_ = try await PCKUser.current()
264+
} catch {
265+
completion(ParseCareKitError.userNotLoggedIn)
266+
return
267+
}
257268
do {
258269
let status = try await ParseHealth.check()
259270
guard status == .ok else {
@@ -293,7 +304,9 @@ public class ParseRemote: OCKRemoteSynchronizable {
293304
let returnError: Error? = nil
294305

295306
let localClock = knowledgeVector.clock(for: self.uuid)
296-
self.subscribeToClock()
307+
Task {
308+
await self.subscribeToClock()
309+
}
297310
ParseRemote.queue.sync {
298311
self.pullRevisionsForConcreteClasses(previousError: returnError, localClock: localClock,
299312
cloudVector: cloudVector,
@@ -411,20 +424,21 @@ public class ParseRemote: OCKRemoteSynchronizable {
411424
public func pushRevisions(deviceRevision: OCKRevisionRecord,
412425
completion: @escaping (Error?) -> Void) {
413426

414-
guard PCKUser.current != nil else {
415-
completion(ParseCareKitError.userNotLoggedIn)
416-
return
417-
}
418-
419-
guard deviceRevision.entities.count > 0 else {
420-
// No revisions need to be pushed
421-
self.isSynchronizing = false
422-
self.parseRemoteDelegate?.successfullyPushedDataToCloud()
423-
completion(nil)
424-
return
425-
}
426-
427427
Task {
428+
do {
429+
_ = try await PCKUser.current()
430+
} catch {
431+
completion(ParseCareKitError.userNotLoggedIn)
432+
return
433+
}
434+
435+
guard deviceRevision.entities.count > 0 else {
436+
// No revisions need to be pushed
437+
self.isSynchronizing = false
438+
self.parseRemoteDelegate?.successfullyPushedDataToCloud()
439+
completion(nil)
440+
return
441+
}
428442
do {
429443
let status = try await ParseHealth.check()
430444
guard status == .ok else {

0 commit comments

Comments
 (0)