Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 committed Apr 21, 2023
1 parent c0b5578 commit d46bf77
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 575 deletions.
6 changes: 0 additions & 6 deletions ParseCareKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
70F2E187254EFC8000B2EA5C /* ParseCareKitConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9119D60A24561B02001B7AA3 /* ParseCareKitConstants.swift */; };
70F2E188254EFC8000B2EA5C /* PCKUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9119D60C24561B22001B7AA3 /* PCKUtility.swift */; };
70F2E189254EFC8000B2EA5C /* ParseRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 916570D62462DABC008F2997 /* ParseRemote.swift */; };
70F2E18A254EFC8000B2EA5C /* PCKSynchronizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91D5287924813AF70022292B /* PCKSynchronizable.swift */; };
70F2E18C254EFC8000B2EA5C /* PCKVersionable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 700775A92522686D00EC0EDA /* PCKVersionable.swift */; };
70F2E18D254EFC8000B2EA5C /* PCKClock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91AA07222466F0CD00B39452 /* PCKClock.swift */; };
70F2E18F254EFC8000B2EA5C /* PCKTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9119D5FA24561A28001B7AA3 /* PCKTask.swift */; };
Expand Down Expand Up @@ -100,7 +99,6 @@
9181F1A729EC48B700C50391 /* PCKEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9181F1A529EC48B700C50391 /* PCKEntity.swift */; };
918F07EE247D66C800C3A205 /* PCKObjectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 918F07ED247D66C800C3A205 /* PCKObjectable.swift */; };
91AA07232466F0CD00B39452 /* PCKClock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91AA07222466F0CD00B39452 /* PCKClock.swift */; };
91D5287A24813AF70022292B /* PCKSynchronizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91D5287924813AF70022292B /* PCKSynchronizable.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -209,7 +207,6 @@
9181F1A529EC48B700C50391 /* PCKEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PCKEntity.swift; sourceTree = "<group>"; };
918F07ED247D66C800C3A205 /* PCKObjectable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PCKObjectable.swift; sourceTree = "<group>"; };
91AA07222466F0CD00B39452 /* PCKClock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PCKClock.swift; sourceTree = "<group>"; };
91D5287924813AF70022292B /* PCKSynchronizable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PCKSynchronizable.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -434,7 +431,6 @@
700B0ED2270DD62200EEF103 /* PCKObjectable+async.swift */,
700B0ED8270DDF5600EEF103 /* PCKObjectable+combine.swift */,
70B5578227A74113002C39D4 /* PCKRoleable.swift */,
91D5287924813AF70022292B /* PCKSynchronizable.swift */,
700775A92522686D00EC0EDA /* PCKVersionable.swift */,
700B0ED5270DD7D900EEF103 /* PCKVersionable+async.swift */,
700B0EDB270DE0C400EEF103 /* PCKVersionable+combine.swift */,
Expand Down Expand Up @@ -732,7 +728,6 @@
700B0ED4270DD62200EEF103 /* PCKObjectable+async.swift in Sources */,
70F2E185254EFC8000B2EA5C /* PCKCarePlan.swift in Sources */,
910734BB29E447ED002169C2 /* RemoteSynchronizing.swift in Sources */,
70F2E18A254EFC8000B2EA5C /* PCKSynchronizable.swift in Sources */,
709D1819258699840002E772 /* ParseRemoteDelegate.swift in Sources */,
70F2E18C254EFC8000B2EA5C /* PCKVersionable.swift in Sources */,
700B0EDA270DDF5600EEF103 /* PCKObjectable+combine.swift in Sources */,
Expand Down Expand Up @@ -776,7 +771,6 @@
91226D56274AC1EF00B5C2DF /* OCKContact+Parse.swift in Sources */,
9181F1A329EC47D800C50391 /* PCKRevisionRecord.swift in Sources */,
91226D54274AC1DB00B5C2DF /* OCKCarePlan+Parse.swift in Sources */,
91D5287A24813AF70022292B /* PCKSynchronizable.swift in Sources */,
709D1818258699840002E772 /* ParseRemoteDelegate.swift in Sources */,
70B5578327A74113002C39D4 /* PCKRoleable.swift in Sources */,
916570D72462DABC008F2997 /* ParseRemote.swift in Sources */,
Expand Down
57 changes: 0 additions & 57 deletions Sources/ParseCareKit/Models/PCKCarePlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,63 +143,6 @@ public struct PCKCarePlan: PCKVersionable {
}
}

public func addToCloud(_ delegate: ParseRemoteDelegate? = nil,
completion: @escaping(Result<PCKSynchronizable, Error>) -> Void) {
self.save(completion: completion)
}

public func pullRevisions(since localClock: Int,
cloudClock: OCKRevisionRecord.KnowledgeVector,
remoteID: String,
mergeRevision: @escaping (Result<OCKRevisionRecord, ParseError>) -> Void) {

let query = Self.query(ObjectableKey.logicalClock >= localClock,
ObjectableKey.remoteID == remoteID)
.order([.ascending(ObjectableKey.logicalClock), .ascending(ObjectableKey.updatedDate)])
.includeAll()
query.find { results in

switch results {

case .success(let carePlans):
let pulled = carePlans.compactMap {try? $0.convertToCareKit()}
let entities = pulled.compactMap {OCKEntity.carePlan($0)}
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(.success(revision))
case .failure(let error):

switch error.code {
case .internalServer, .objectNotFound:
// 1 - this column hasn't been added. 101 - Query returned no results
// If the query was looking in a column that wasn't a default column,
// it will return nil if the table doesn't contain the custom column
// Saving the new item with the custom column should resolve the issue
Logger.carePlan.debug("Warning, the table either doesn't exist or is missing the column \"\(ObjectableKey.logicalClock, privacy: .private)\". It should be fixed during the first sync... ParseError: \(error.localizedDescription, privacy: .private)")
default:
Logger.carePlan.debug("An unexpected error occured \(error, privacy: .private)")
}
mergeRevision(.failure(error))
}
}
}

public func pushRevision(_ delegate: ParseRemoteDelegate? = nil,
cloudClock: Int,
remoteID: String,
completion: @escaping (Error?) -> Void) {
var mutableCarePlan = self
mutableCarePlan.logicalClock = cloudClock // Stamp Entity
mutableCarePlan.remoteID = remoteID
mutableCarePlan.addToCloud { result in
switch result {
case .success:
completion(nil)
case .failure(let error):
completion(error)
}
}
}

public static func copyValues(from other: PCKCarePlan, to here: PCKCarePlan) throws -> Self {
var here = here
here.copyVersionedValues(from: other)
Expand Down
58 changes: 0 additions & 58 deletions Sources/ParseCareKit/Models/PCKContact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,64 +174,6 @@ public struct PCKContact: PCKVersionable {
}
}

public func addToCloud(_ delegate: ParseRemoteDelegate? = nil,
completion: @escaping(Result<PCKSynchronizable, Error>) -> Void) {
self.save(completion: completion)
}

public func pullRevisions(since localClock: Int,
cloudClock: OCKRevisionRecord.KnowledgeVector,
remoteID: String,
mergeRevision: @escaping (Result<OCKRevisionRecord, ParseError>) -> Void) {

let query = Self.query(ObjectableKey.logicalClock >= localClock,
ObjectableKey.remoteID == remoteID)
.order([.ascending(ObjectableKey.logicalClock), .ascending(ObjectableKey.updatedDate)])
.includeAll()
query.find { results in

switch results {

case .success(let contacts):
let pulled = contacts.compactMap {try? $0.convertToCareKit()}
let entities = pulled.compactMap {OCKEntity.contact($0)}
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(.success(revision))

case .failure(let error):

switch error.code {
// 1 - this column hasn't been added. 101 - Query returned no results
// If the query was looking in a column that wasn't a default column,
// it will return nil if the table doesn't contain the custom column
// Saving the new item with the custom column should resolve the issue
case .internalServer, .objectNotFound:
Logger.contact.debug("Warning, the table either doesn't exist or is missing the column \"\(ObjectableKey.logicalClock, privacy: .private)\". It should be fixed during the first sync... ParseError: \(error.localizedDescription, privacy: .private)")
default:
Logger.contact.debug("An unexpected error occured \(error, privacy: .private)")
}
mergeRevision(.failure(error))
}
}
}

public func pushRevision(_ delegate: ParseRemoteDelegate? = nil,
cloudClock: Int,
remoteID: String,
completion: @escaping (Error?) -> Void) {
var mutableContact = self
mutableContact.logicalClock = cloudClock // Stamp Entity
mutableContact.remoteID = remoteID
mutableContact.addToCloud { result in
switch result {
case .success:
completion(nil)
case .failure(let error):
completion(error)
}
}
}

public static func copyValues(from other: PCKContact, to here: PCKContact) throws -> Self {
var copy = here
copy.copyVersionedValues(from: other)
Expand Down
56 changes: 0 additions & 56 deletions Sources/ParseCareKit/Models/PCKHealthKitTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,62 +158,6 @@ public struct PCKHealthKitTask: PCKVersionable {
}
}

public func addToCloud(_ delegate: ParseRemoteDelegate? = nil,
completion: @escaping(Result<PCKSynchronizable, Error>) -> Void) {
self.save(completion: completion)
}

public func pullRevisions(since localClock: Int,
cloudClock: OCKRevisionRecord.KnowledgeVector,
remoteID: String,
mergeRevision: @escaping (Result<OCKRevisionRecord, ParseError>) -> Void) {

let query = Self.query(ObjectableKey.logicalClock >= localClock,
ObjectableKey.remoteID == remoteID)
.order([.ascending(ObjectableKey.logicalClock), .ascending(ObjectableKey.updatedDate)])
.includeAll()
query.find { results in
switch results {

case .success(let tasks):
let pulled = tasks.compactMap {try? $0.convertToCareKit()}
let entities = pulled.compactMap {OCKEntity.healthKitTask($0)}
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(.success(revision))
case .failure(let error):

switch error.code {
case .internalServer, .objectNotFound:
// 1 - this column hasn't been added. 101 - Query returned no results
// If the query was looking in a column that wasn't a default column,
// it will return nil if the table doesn't contain the custom column
// Saving the new item with the custom column should resolve the issue
Logger.healthKitTask.debug("Warning, the table either doesn't exist or is missing the column \"\(ObjectableKey.logicalClock, privacy: .private)\". It should be fixed during the first sync... ParseError: \(error, privacy: .private)")
default:
Logger.healthKitTask.debug("An unexpected error occured \(error, privacy: .private)")
}
mergeRevision(.failure(error))
}
}
}

public func pushRevision(_ delegate: ParseRemoteDelegate? = nil,
cloudClock: Int,
remoteID: String,
completion: @escaping (Error?) -> Void) {
var mutableTask = self
mutableTask.logicalClock = cloudClock // Stamp Entity
mutableTask.remoteID = remoteID
mutableTask.addToCloud { result in
switch result {
case .success:
completion(nil)
case .failure(let error):
completion(error)
}
}
}

public static func copyValues(from other: PCKHealthKitTask, to here: PCKHealthKitTask) throws -> PCKHealthKitTask {
var here = here
here.copyVersionedValues(from: other)
Expand Down
80 changes: 20 additions & 60 deletions Sources/ParseCareKit/Models/PCKOutcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import os.log
/// outcome of an event corresponding to a task. An outcome may have 0 or more values associated with it.
/// For example, a task that asks a patient to measure their temperature will have events whose outcome
/// will contain a single value representing the patient's temperature.
public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
public struct PCKOutcome: PCKVersionable {

public var previousVersionUUIDs: [UUID]? {
willSet {
Expand Down Expand Up @@ -159,62 +159,6 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
}
}

public func addToCloud(_ delegate: ParseRemoteDelegate?,
completion: @escaping(Result<PCKSynchronizable, Error>) -> Void) {
self.fetchLocalDataAndSave(delegate, completion: completion)
}

public func pullRevisions(since localClock: Int,
cloudClock: OCKRevisionRecord.KnowledgeVector,
remoteID: String,
mergeRevision: @escaping (Result<OCKRevisionRecord, ParseError>) -> Void) {

let query = Self.query(ObjectableKey.logicalClock >= localClock,
ObjectableKey.remoteID == remoteID)
.order([.ascending(ObjectableKey.logicalClock), .ascending(ObjectableKey.updatedDate)])
.includeAll()
query.find { results in
switch results {

case .success(let outcomes):
let pulled = outcomes.compactMap {try? $0.convertToCareKit()}
let entities = pulled.compactMap {OCKEntity.outcome($0)}
let revision = OCKRevisionRecord(entities: entities, knowledgeVector: cloudClock)
mergeRevision(.success(revision))
case .failure(let error):

switch error.code {
case .internalServer, .objectNotFound:
// 1 - this column hasn't been added. 101 - Query returned no results
// If the query was looking in a column that wasn't a default column,
// it will return nil if the table doesn't contain the custom column
// Saving the new item with the custom column should resolve the issue
Logger.outcome.debug("Warning, the table either doesn't exist or is missing the column \"\(ObjectableKey.logicalClock, privacy: .private)\". It should be fixed during the first sync... ParseError: \(error, privacy: .private)")
default:
Logger.outcome.debug("An unexpected error occured \(error, privacy: .private)")
}
mergeRevision(.failure(error))
}
}
}

public func pushRevision(_ delegate: ParseRemoteDelegate?,
cloudClock: Int,
remoteID: String,
completion: @escaping (Error?) -> Void) {
var mutableOutcome = self
mutableOutcome.logicalClock = cloudClock // Stamp Entity
mutableOutcome.remoteID = remoteID
mutableOutcome.addToCloud(delegate) { result in
switch result {
case .success:
completion(nil)
case .failure(let error):
completion(error)
}
}
}

public static func copyValues(from other: PCKOutcome, to here: PCKOutcome) throws -> Self {
var here = here
here.copyCommonValues(from: other)
Expand Down Expand Up @@ -268,7 +212,7 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
}

public func fetchLocalDataAndSave(_ delegate: ParseRemoteDelegate?,
completion: @escaping(Result<PCKSynchronizable, Error>) -> Void) {
completion: @escaping(Result<Self, Error>) -> Void) {
guard let taskUUID = taskUUID,
let taskOccurrenceIndex = taskOccurrenceIndex else {
completion(.failure(ParseCareKitError.errorString("""
Expand Down Expand Up @@ -298,13 +242,29 @@ public struct PCKOutcome: PCKVersionable, PCKSynchronizable {
guard let event = task.schedule.event(forOccurrenceIndex: taskOccurrenceIndex) else {
mutableOutcome.startDate = nil
mutableOutcome.endDate = nil
mutableOutcome.save(completion: completion)
mutableOutcome.save { result in
switch result {
case .success(let outcome):
completion(.success(outcome))
case .failure(let error):
let parseCareKitError = ParseCareKitError.errorString(error.localizedDescription)
completion(.failure(parseCareKitError))
}
}
return
}

mutableOutcome.startDate = event.start
mutableOutcome.endDate = event.end
mutableOutcome.save(completion: completion)
mutableOutcome.save { result in
switch result {
case .success(let outcome):
completion(.success(outcome))
case .failure(let error):
let parseCareKitError = ParseCareKitError.errorString(error.localizedDescription)
completion(.failure(parseCareKitError))
}
}
case .failure(let error):
completion(.failure(error))
}
Expand Down
Loading

0 comments on commit d46bf77

Please sign in to comment.