Skip to content

Commit 4f6a1c7

Browse files
committed
Add previous and next pointers to each Object
1 parent c69ef5b commit 4f6a1c7

File tree

8 files changed

+181
-21
lines changed

8 files changed

+181
-21
lines changed

Sources/ParseCareKit/Models/PCKCarePlan.swift

+28-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,34 @@ import os.log
2121
/// time about why the changes were made.
2222
public struct PCKCarePlan: PCKVersionable {
2323

24+
public var previousVersionUUIDs: [UUID]? {
25+
willSet {
26+
guard let newValue = newValue else {
27+
previousVersions = nil
28+
return
29+
}
30+
var newPreviousVersions = [Pointer<Self>]()
31+
newValue.forEach { newPreviousVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
32+
previousVersions = newPreviousVersions
33+
}
34+
}
35+
36+
public var nextVersionUUIDs: [UUID]? {
37+
willSet {
38+
guard let newValue = newValue else {
39+
nextVersions = nil
40+
return
41+
}
42+
var newNextVersions = [Pointer<Self>]()
43+
newValue.forEach { newNextVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
44+
nextVersions = newNextVersions
45+
}
46+
}
47+
48+
public var previousVersions: [Pointer<Self>]?
49+
50+
public var nextVersions: [Pointer<Self>]?
51+
2452
public var effectiveDate: Date?
2553

2654
public var entityId: String?
@@ -71,10 +99,6 @@ public struct PCKCarePlan: PCKVersionable {
7199

72100
public var originalData: Data?
73101

74-
public var nextVersionUUIDs: [UUID]?
75-
76-
public var previousVersionUUIDs: [UUID]?
77-
78102
/// The patient to whom this care plan belongs.
79103
public var patient: PCKPatient? {
80104
didSet {

Sources/ParseCareKit/Models/PCKContact.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,33 @@ import os.log
2121
/// least a name, and may optionally have numerous other addresses at which to be contacted.
2222
public struct PCKContact: PCKVersionable {
2323

24-
public var nextVersionUUIDs: [UUID]?
24+
public var previousVersionUUIDs: [UUID]? {
25+
willSet {
26+
guard let newValue = newValue else {
27+
previousVersions = nil
28+
return
29+
}
30+
var newPreviousVersions = [Pointer<Self>]()
31+
newValue.forEach { newPreviousVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
32+
previousVersions = newPreviousVersions
33+
}
34+
}
35+
36+
public var nextVersionUUIDs: [UUID]? {
37+
willSet {
38+
guard let newValue = newValue else {
39+
nextVersions = nil
40+
return
41+
}
42+
var newNextVersions = [Pointer<Self>]()
43+
newValue.forEach { newNextVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
44+
nextVersions = newNextVersions
45+
}
46+
}
47+
48+
public var previousVersions: [Pointer<Self>]?
2549

26-
public var previousVersionUUIDs: [UUID]?
50+
public var nextVersions: [Pointer<Self>]?
2751

2852
public var effectiveDate: Date?
2953

Sources/ParseCareKit/Models/PCKHealthKitTask.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,33 @@ import os.log
2323
/// their daily completion rings.
2424
public struct PCKHealthKitTask: PCKVersionable {
2525

26-
public var nextVersionUUIDs: [UUID]?
26+
public var previousVersionUUIDs: [UUID]? {
27+
willSet {
28+
guard let newValue = newValue else {
29+
previousVersions = nil
30+
return
31+
}
32+
var newPreviousVersions = [Pointer<Self>]()
33+
newValue.forEach { newPreviousVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
34+
previousVersions = newPreviousVersions
35+
}
36+
}
37+
38+
public var nextVersionUUIDs: [UUID]? {
39+
willSet {
40+
guard let newValue = newValue else {
41+
nextVersions = nil
42+
return
43+
}
44+
var newNextVersions = [Pointer<Self>]()
45+
newValue.forEach { newNextVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
46+
nextVersions = newNextVersions
47+
}
48+
}
49+
50+
public var previousVersions: [Pointer<Self>]?
2751

28-
public var previousVersionUUIDs: [UUID]?
52+
public var nextVersions: [Pointer<Self>]?
2953

3054
public var effectiveDate: Date?
3155

Sources/ParseCareKit/Models/PCKOutcome.swift

+38-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,33 @@ import os.log
2121
/// will contain a single value representing the patient's temperature.
2222
public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
2323

24-
public var previousVersionUUIDs: [UUID]?
24+
public var previousVersionUUIDs: [UUID]? {
25+
willSet {
26+
guard let newValue = newValue else {
27+
previousVersions = nil
28+
return
29+
}
30+
var newPreviousVersions = [Pointer<Self>]()
31+
newValue.forEach { newPreviousVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
32+
previousVersions = newPreviousVersions
33+
}
34+
}
35+
36+
public var nextVersionUUIDs: [UUID]? {
37+
willSet {
38+
guard let newValue = newValue else {
39+
nextVersions = nil
40+
return
41+
}
42+
var newNextVersions = [Pointer<Self>]()
43+
newValue.forEach { newNextVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
44+
nextVersions = newNextVersions
45+
}
46+
}
47+
48+
public var previousVersions: [Pointer<Self>]?
2549

26-
public var nextVersionUUIDs: [UUID]?
50+
public var nextVersions: [Pointer<Self>]?
2751

2852
public var effectiveDate: Date?
2953

@@ -186,7 +210,7 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
186210
return
187211
}
188212
var updated = self
189-
updated = updated.copyRelationalEntities(previousVersion)
213+
updated = updated.copyRelational(previousVersion)
190214
updated.addToCloud(delegate, completion: completion)
191215

192216
default:
@@ -206,7 +230,6 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
206230
}
207231
completion(.failure(error))
208232
}
209-
210233
}
211234
}
212235

@@ -260,7 +283,17 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
260283
var mutableOutcome = self
261284
mutableOutcome.logicalClock = cloudClock // Stamp Entity
262285
mutableOutcome.remoteID = remoteID
286+
mutableOutcome.addToCloud(delegate) { result in
287+
288+
switch result {
263289

290+
case .success:
291+
completion(nil)
292+
case .failure(let error):
293+
completion(error)
294+
}
295+
}
296+
/*
264297
guard mutableOutcome.deletedDate != nil else {
265298

266299
mutableOutcome.addToCloud(delegate) { result in
@@ -285,7 +318,7 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
285318
case .failure(let error):
286319
completion(error)
287320
}
288-
}
321+
} */
289322
}
290323

291324
public static func copyValues(from other: PCKOutcome, to here: PCKOutcome) throws -> Self {
@@ -317,7 +350,6 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
317350

318351
public func copyRelational(_ parse: PCKOutcome) -> PCKOutcome {
319352
var copy = self
320-
copy = copy.copyRelationalEntities(parse)
321353
if copy.values == nil {
322354
copy.values = .init()
323355
}

Sources/ParseCareKit/Models/PCKPatient.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,33 @@ import os.log
1818
/// An `PCKPatient` is the ParseCareKit equivalent of `OCKPatient`. An `OCKPatient` represents a patient.
1919
public struct PCKPatient: PCKVersionable {
2020

21-
public var nextVersionUUIDs: [UUID]?
21+
public var previousVersionUUIDs: [UUID]? {
22+
willSet {
23+
guard let newValue = newValue else {
24+
previousVersions = nil
25+
return
26+
}
27+
var newPreviousVersions = [Pointer<Self>]()
28+
newValue.forEach { newPreviousVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
29+
previousVersions = newPreviousVersions
30+
}
31+
}
32+
33+
public var nextVersionUUIDs: [UUID]? {
34+
willSet {
35+
guard let newValue = newValue else {
36+
nextVersions = nil
37+
return
38+
}
39+
var newNextVersions = [Pointer<Self>]()
40+
newValue.forEach { newNextVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
41+
nextVersions = newNextVersions
42+
}
43+
}
44+
45+
public var previousVersions: [Pointer<Self>]?
2246

23-
public var previousVersionUUIDs: [UUID]?
47+
public var nextVersions: [Pointer<Self>]?
2448

2549
public var effectiveDate: Date?
2650

Sources/ParseCareKit/Models/PCKTask.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,33 @@ import os.log
2323
/// their daily completion rings.
2424
public struct PCKTask: PCKVersionable {
2525

26-
public var nextVersionUUIDs: [UUID]?
26+
public var previousVersionUUIDs: [UUID]? {
27+
willSet {
28+
guard let newValue = newValue else {
29+
previousVersions = nil
30+
return
31+
}
32+
var newPreviousVersions = [Pointer<Self>]()
33+
newValue.forEach { newPreviousVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
34+
previousVersions = newPreviousVersions
35+
}
36+
}
37+
38+
public var nextVersionUUIDs: [UUID]? {
39+
willSet {
40+
guard let newValue = newValue else {
41+
nextVersions = nil
42+
return
43+
}
44+
var newNextVersions = [Pointer<Self>]()
45+
newValue.forEach { newNextVersions.append(Pointer<Self>(objectId: $0.uuidString)) }
46+
nextVersions = newNextVersions
47+
}
48+
}
49+
50+
public var previousVersions: [Pointer<Self>]?
2751

28-
public var previousVersionUUIDs: [UUID]?
52+
public var nextVersions: [Pointer<Self>]?
2953

3054
public var effectiveDate: Date?
3155

Sources/ParseCareKit/Protocols/PCKObjectable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ extension PCKObjectable {
116116

117117
extension PCKObjectable {
118118

119-
mutating func copyRelationalEntities(_ parse: Self) -> Self {
119+
func copyRelationalEntities(_ parse: Self) -> Self {
120120
var current = self
121121
current.notes = parse.notes
122122
return current

Sources/ParseCareKit/Protocols/PCKVersionable.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,22 @@ import os.log
1818
Objects that conform to the `PCKVersionable` protocol are Parse interpretations of `OCKVersionedObjectCompatible` objects.
1919
*/
2020
public protocol PCKVersionable: PCKObjectable, PCKSynchronizable {
21-
/// The UUID of the previous version of this object, or nil if there is no previous version.
21+
/// The UUIDs of the previous version of this object, or nil if there is no previous version.
2222
/// The UUIDs are in no particular order.
2323
var previousVersionUUIDs: [UUID]? { get set }
2424

25-
/// The UUID of the next version of this object, or nil if there is no next version.
25+
/// The UUIDs of the next version of this object, or nil if there is no next version.
2626
/// The UUIDs are in no particular order.
2727
var nextVersionUUIDs: [UUID]? { get set }
2828

29+
/// The previous versions of this object, or nil if there is no previous version.
30+
/// The versions are in no particular order.
31+
var previousVersions: [Pointer<Self>]? { get set }
32+
33+
/// The next versions of this object, or nil if there is no next version.
34+
/// The versions are in no particular order.
35+
var nextVersions: [Pointer<Self>]? { get set }
36+
2937
/// The date that this version of the object begins to take precedence over the previous version.
3038
/// Often this will be the same as the `createdDate`, but is not required to be.
3139
var effectiveDate: Date? { get set }

0 commit comments

Comments
 (0)