diff --git a/CareKitEssentials.xcodeproj/project.pbxproj b/CareKitEssentials.xcodeproj/project.pbxproj index 203b7159..a787ee3c 100644 --- a/CareKitEssentials.xcodeproj/project.pbxproj +++ b/CareKitEssentials.xcodeproj/project.pbxproj @@ -453,6 +453,7 @@ LastSwiftMigration = 9999; LastSwiftUpdateCheck = 1540; LastUpgradeCheck = 1540; + ORGANIZATIONNAME = "Network Reconnaissance Lab"; TargetAttributes = { 70C422CE2C3B6C7600E6DC51 = { CreatedOnToolsVersion = 15.4; diff --git a/Package.swift b/Package.swift index 0a48a862..10d45249 100644 --- a/Package.swift +++ b/Package.swift @@ -8,22 +8,36 @@ let package = Package( products: [ .library( name: "CareKitEssentials", - targets: ["CareKitEssentials"]) + targets: ["CareKitEssentials"] + ) ], dependencies: [ - .package(url: "https://github.com/cbaker6/CareKit.git", - .upToNextMajor(from: "3.0.0-beta.12")) + .package( + url: "https://github.com/cbaker6/CareKit.git", + .upToNextMajor(from: "3.0.0-beta.12") + ) ], targets: [ .target( name: "CareKitEssentials", dependencies: [ - .product(name: "CareKit", package: "CareKit"), - .product(name: "CareKitStore", package: "CareKit"), - .product(name: "CareKitUI", package: "CareKit") - ]), + .product( + name: "CareKit", + package: "CareKit" + ), + .product( + name: "CareKitStore", + package: "CareKit" + ), + .product( + name: "CareKitUI", + package: "CareKit" + ) + ] + ), .testTarget( name: "CareKitEssentialsTests", - dependencies: ["CareKitEssentials"]) + dependencies: ["CareKitEssentials"] + ) ] ) diff --git a/Sources/CareKitEssentials/Extensions/OCKAnyOutcome+Sequence.swift b/Sources/CareKitEssentials/Extensions/OCKAnyOutcome+Sequence.swift index 94d1971b..13083d95 100644 --- a/Sources/CareKitEssentials/Extensions/OCKAnyOutcome+Sequence.swift +++ b/Sources/CareKitEssentials/Extensions/OCKAnyOutcome+Sequence.swift @@ -3,6 +3,7 @@ // CareKitEssentials // // Created by Corey Baker on 7/7/24. +// Copyright © 2024 Network Reconnaissance Lab. All rights reserved. // import CareKitStore @@ -11,8 +12,8 @@ import Foundation public extension Sequence where Element: OCKAnyOutcome { /** - Returns the `OCKAnyOutcome` sorted in order from newest to oldest with respect to a given `KeyPath`. - When necessary, can specify a cutoff value for the respective `KeyPath` to be less than or equal to. + Returns the `OCKAnyOutcome` sorted in order from greatest to lowest with respect to a given `KeyPath`. + When necessary, can specify a max value for the respective `KeyPath` to be less than or equal to. - parameter keyPath: An optional `Comparable` `KeyPath` to sort the `OCKAnyOutcome`'s by. - parameter lessThanEqualTo: The value that the `keyPath` of all `OCKAnyOutcome`'s should @@ -21,7 +22,7 @@ public extension Sequence where Element: OCKAnyOutcome { - throws: An error when the `keyPath` cannot be unwrapped for any of the `OCKAnyOutcome` values in the array. */ - func sortedNewestToOldest( + func sortedByGreatest( _ keyPath: KeyPath, lessThanEqualTo value: V? = nil ) throws -> [Element] where V: Comparable { @@ -52,15 +53,15 @@ public extension Sequence where Element: OCKAnyOutcome { } /** - Returns the `OCKAnyOutcome` sorted in order from newest to oldest with respect to a given `KeyPath`. - When necessary, can specify a cutoff value for the respective `KeyPath` to be less than or equal to. + Returns the `OCKAnyOutcome` sorted in order from greatest to lowest with respect to a given `KeyPath`. + When necessary, can specify a max value for the respective `KeyPath` to be less than or equal to. - parameter keyPath: A `Comparable` `KeyPath` to sort the `OCKAnyOutcome`'s by. - parameter lessThanEqualTo: The value that the `keyPath` of all `OCKAnyOutcome`'s should be less than or equal to. If this value is `nil`, the - returns: Returns an array of `OCKAnyOutcome` sorted from newest to oldest with respect to `keyPath`. */ - func sortedNewestToOldest( + func sortedByGreatest( _ keyPath: KeyPath, lessThanEqualTo value: V? = nil ) -> [Element] where V: Comparable { diff --git a/Tests/CareKitEssentialsTests/OCKOutcomeExtensionsTests.swift b/Tests/CareKitEssentialsTests/OCKOutcomeExtensionsTests.swift index 81f48c51..3a9e4602 100644 --- a/Tests/CareKitEssentialsTests/OCKOutcomeExtensionsTests.swift +++ b/Tests/CareKitEssentialsTests/OCKOutcomeExtensionsTests.swift @@ -26,7 +26,7 @@ final class OCKOutcomeExtensionsTests: XCTestCase { // Test sorted properly XCTAssertNotEqual(firstOutcome, secondOutcome) - let sortedByCreatedDate = try outcomes.sortedNewestToOldest( + let sortedByCreatedDate = try outcomes.sortedByGreatest( \.createdDate ) XCTAssertEqual(sortedByCreatedDate.count, 2) @@ -34,13 +34,13 @@ final class OCKOutcomeExtensionsTests: XCTestCase { XCTAssertEqual(sortedByCreatedDate.last, firstOutcome) // Test lessThanKeyPath - let sortedByCreatedDate2 = try outcomes.sortedNewestToOldest( + let sortedByCreatedDate2 = try outcomes.sortedByGreatest( \.createdDate, lessThanEqualTo: firstDate ) XCTAssertEqual(sortedByCreatedDate2.count, 1) XCTAssertEqual(sortedByCreatedDate2.first, firstOutcome) - let sortedByCreatedDate3 = try outcomes.sortedNewestToOldest( + let sortedByCreatedDate3 = try outcomes.sortedByGreatest( \.createdDate, lessThanEqualTo: secondDate ) @@ -49,7 +49,7 @@ final class OCKOutcomeExtensionsTests: XCTestCase { XCTAssertEqual(sortedByCreatedDate3.last, firstOutcome) // Test KeyPath of nil should throw error - XCTAssertThrowsError(try outcomes.sortedNewestToOldest( + XCTAssertThrowsError(try outcomes.sortedByGreatest( \.updatedDate )) } @@ -74,7 +74,7 @@ final class OCKOutcomeExtensionsTests: XCTestCase { // Test sorted properly XCTAssertNotEqual(firstOutcome, secondOutcome) - let sortedByOccurrenceIndex = outcomes.sortedNewestToOldest( + let sortedByOccurrenceIndex = outcomes.sortedByGreatest( \.taskOccurrenceIndex ) XCTAssertEqual(sortedByOccurrenceIndex.count, 2) @@ -82,13 +82,13 @@ final class OCKOutcomeExtensionsTests: XCTestCase { XCTAssertEqual(sortedByOccurrenceIndex.last, firstOutcome) // Test lessThanKeyPath - let sortedByOccurrenceIndex2 = outcomes.sortedNewestToOldest( + let sortedByOccurrenceIndex2 = outcomes.sortedByGreatest( \.taskOccurrenceIndex, lessThanEqualTo: firstIndex ) XCTAssertEqual(sortedByOccurrenceIndex2.count, 1) XCTAssertEqual(sortedByOccurrenceIndex2.first, firstOutcome) - let sortedByOccurrenceIndex3 = outcomes.sortedNewestToOldest( + let sortedByOccurrenceIndex3 = outcomes.sortedByGreatest( \.taskOccurrenceIndex, lessThanEqualTo: secondIndex )