@@ -13,14 +13,15 @@ final class Key: Identifiable {
1313 var longitude : Double ?
1414 var radiusMeters : Double ?
1515 var radiusKind : LocationRadiusKind ?
16+ var sortIndex : Int = 0
1617 private( set) var hashedValue : String
1718 private( set) var salt : String
1819
1920 private static let pbkdf2Rounds : UInt32 = 100_000
2021 private static let saltLength = 16
2122 private static let hashLength = 32
2223
23- init ( name : String , type : KeyType , rawValue : String , scanKind : ScanCodeKind ? = nil ) {
24+ init ( name : String , type : KeyType , rawValue : String , scanKind : ScanCodeKind ? = nil , sortIndex : Int = 0 ) {
2425 id = UUID ( )
2526 self . name = name
2627 self . type = type
@@ -29,12 +30,20 @@ final class Key: Identifiable {
2930 longitude = nil
3031 radiusMeters = nil
3132 radiusKind = nil
33+ self . sortIndex = sortIndex
3234 let salt = Self . generateSalt ( )
3335 self . salt = salt
3436 hashedValue = Self . hash ( unhashedString : rawValue , salt : salt )
3537 }
3638
37- init ( name : String , latitude : Double , longitude : Double , radiusMeters : Double , radiusKind : LocationRadiusKind ) {
39+ init (
40+ name : String ,
41+ latitude : Double ,
42+ longitude : Double ,
43+ radiusMeters : Double ,
44+ radiusKind : LocationRadiusKind ,
45+ sortIndex : Int = 0
46+ ) {
3847 id = UUID ( )
3948 self . name = name
4049 type = . location
@@ -43,6 +52,7 @@ final class Key: Identifiable {
4352 self . longitude = longitude
4453 self . radiusMeters = radiusMeters
4554 self . radiusKind = radiusKind
55+ self . sortIndex = sortIndex
4656 salt = " "
4757 hashedValue = " "
4858 }
@@ -69,7 +79,6 @@ final class Key: Identifiable {
6979 return Self . hash ( unhashedString : unhashedId , salt : salt ) == hashedValue
7080 }
7181
72- /// Whether `location` falls inside this key's saved radius.
7382 func matches ( location : CLLocation ) -> Bool {
7483 guard type == . location , let latitude , let longitude , let radiusMeters else { return false }
7584 let target = CLLocation ( latitude : latitude , longitude : longitude )
@@ -80,13 +89,10 @@ final class Key: Identifiable {
8089 keys . filter { $0 . type == . location }
8190 }
8291
83- /// All location keys share a single kind; this returns it (or `nil` if none exist).
8492 static func existingLocationKind ( in keys : [ Key ] ) -> LocationRadiusKind ? {
8593 locationKeys ( in : keys ) . first ? . radiusKind
8694 }
8795
88- /// Verifies the location keys against the user's current position.
89- /// Unblock radii pass when inside any zone; block radii pass when outside every zone.
9096 static func locationKeyVerifies ( keys : [ Key ] , location : CLLocation ) -> Bool {
9197 let locKeys = locationKeys ( in : keys )
9298 guard let kind = locKeys . first ? . radiusKind else { return false }
0 commit comments