Skip to content

Commit

Permalink
Merge pull request #623 from daleswift/prevent-crash-unregisterSuperP…
Browse files Browse the repository at this point in the history
…roperty

Prevent crashes in unregisterSuperProperty
  • Loading branch information
zihejia authored Jan 17, 2024
2 parents a8c862f + ec16672 commit ffd0d35
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Sources/MixpanelInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1320,9 +1320,14 @@ extension MixpanelInstance {
public func unregisterSuperProperty(_ propertyName: String) {
trackingQueue.async { [weak self] in
guard let self = self else { return }
self.superProperties = self.trackInstance.unregisterSuperProperty(propertyName,
let updatedSuperProperties = self.trackInstance.unregisterSuperProperty(propertyName,
superProperties: self.superProperties)
MixpanelPersistence.saveSuperProperties(superProperties: self.superProperties, instanceName: self.name)
self.readWriteLock.write {
self.superProperties = updatedSuperProperties
}
self.readWriteLock.read {
MixpanelPersistence.saveSuperProperties(superProperties: self.superProperties, instanceName: self.name)
}
}
}

Expand All @@ -1337,8 +1342,12 @@ extension MixpanelInstance {
var superPropertiesShadow = self.superProperties
self.trackInstance.updateSuperProperty(update,
superProperties: &superPropertiesShadow)
self.superProperties = superPropertiesShadow
MixpanelPersistence.saveSuperProperties(superProperties: self.superProperties, instanceName: self.name)
self.readWriteLock.write {
self.superProperties = superPropertiesShadow
}
self.readWriteLock.read {
MixpanelPersistence.saveSuperProperties(superProperties: self.superProperties, instanceName: self.name)
}
}
}

Expand Down

0 comments on commit ffd0d35

Please sign in to comment.