Skip to content

Commit 8fdb2e4

Browse files
authored
Merge pull request #6 from codykerns/cody/fix-persist-issue
Fix issue with persisting new id
2 parents 2d91254 + 4b517f5 commit 8fdb2e4

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

Sources/StableID/StableID.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ public class StableID {
6060
}
6161
}
6262

63-
_stableID = StableID(_id: identifier, _idGenerator: idGenerator)
63+
let stableID = StableID(_id: identifier, _idGenerator: idGenerator)
64+
stableID.persist(identifier: identifier)
6465

66+
self._stableID = stableID
67+
6568
self.logger.log(type: .info, message: "Configured StableID. Current user ID: \(identifier)")
6669

6770
NotificationCenter.default.addObserver(Self.shared,
@@ -90,8 +93,7 @@ public class StableID {
9093
Self.logger.log(type: .info, message: "Setting StableID to \(adjustedId)")
9194

9295
Self.shared._id = adjustedId
93-
self.setLocal(key: Constants.StableID_Key_Identifier, value: adjustedId)
94-
self.setRemote(key: Constants.StableID_Key_Identifier, value: adjustedId)
96+
self.persist(identifier: adjustedId)
9597

9698
self.delegate?.didChangeID(newID: adjustedId)
9799
}
@@ -104,12 +106,9 @@ public class StableID {
104106
self.setIdentity(value: newID)
105107
}
106108

107-
private func setLocal(key: String, value: String) {
108-
Self._localStore?.set(value, forKey: key)
109-
}
110-
111-
private func setRemote(key: String, value: String) {
112-
Self._remoteStore.set(value, forKey: key)
109+
private func persist(identifier: String) {
110+
Self._localStore?.set(identifier, forKey: Constants.StableID_Key_Identifier)
111+
Self._remoteStore.set(identifier, forKey: Constants.StableID_Key_Identifier)
113112
Self._remoteStore.synchronize()
114113
}
115114

0 commit comments

Comments
 (0)