Skip to content

Commit

Permalink
Take strong reference to _publisher to avoid crash on unowned
Browse files Browse the repository at this point in the history
Submitted upstream as jessesquires#112 but upstream latest changes the name of the property wrappers and I'm not bothering to do that here.
  • Loading branch information
nolanw committed Aug 16, 2024
1 parent 977201c commit e2ea69f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/WrappedDefault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public struct WrappedDefault<T: UserDefaultsSerializable> {
// and uses force unwrap
self._publisher = CurrentValueSubject<T, Never>(userDefaults.fetch(keyName))

self._observer = ObserverTrampoline(userDefaults: userDefaults, key: keyName) { [unowned _publisher] in
self._observer = ObserverTrampoline(userDefaults: userDefaults, key: keyName) { [_publisher] in
_publisher.send(userDefaults.fetch(keyName))
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/WrappedDefaultOptional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public struct WrappedDefaultOptional<T: UserDefaultsSerializable> {
self.key = keyName
self._userDefaults = userDefaults
self._publisher = CurrentValueSubject<T?, Never>(userDefaults.fetchOptional(keyName))
self._observer = ObserverTrampoline(userDefaults: userDefaults, key: keyName) { [unowned _publisher] in
self._observer = ObserverTrampoline(userDefaults: userDefaults, key: keyName) { [_publisher] in
_publisher.send(userDefaults.fetchOptional(keyName))
}
}
Expand Down

0 comments on commit e2ea69f

Please sign in to comment.