Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Try to avoid possible [unowned self] crash on iOS 13.4 and Xcode 11.4
Browse files Browse the repository at this point in the history
  • Loading branch information
CozmoNate committed Mar 30, 2020
1 parent c35545a commit 73e9a26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ClassyFlux.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ClassyFlux'
s.version = '1.21.0'
s.version = '1.21.1'
s.summary = 'Flux implementation on Swift'
s.homepage = 'https://github.com/kzlekk/ClassyFlux'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
4 changes: 2 additions & 2 deletions ClassyFlux.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.21.0;
MARKETING_VERSION = 1.21.1;
PRODUCT_BUNDLE_IDENTIFIER = org.kzlekk.ClassyFlux;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = macosx;
Expand All @@ -461,7 +461,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.21.0;
MARKETING_VERSION = 1.21.1;
PRODUCT_BUNDLE_IDENTIFIER = org.kzlekk.ClassyFlux;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = macosx;
Expand Down
4 changes: 3 additions & 1 deletion Flux/FluxAggregator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public class FluxAggregator {
/// - Parameter observingKeyPaths: The list of KeyPath describing the fields in particular state object which should trigger state change handlers.
public func register<State>(store: FluxStore<State>, observing observingKeyPaths: Set<PartialKeyPath<State>> = Set(), queue: OperationQueue = .main) {
storage.register(instance: store as FluxStore<State>)
observers[store.token] = store.addObserver(for: .stateDidChange, queue: queue) { [unowned self] state, changedKeyPaths in
observers[store.token] = store.addObserver(for: .stateDidChange, queue: queue) { [weak self] state, changedKeyPaths in
guard let self = self else { return }

guard observingKeyPaths.isEmpty || !observingKeyPaths.isDisjoint(with: changedKeyPaths) else {
return
}
Expand Down
9 changes: 6 additions & 3 deletions Flux/FluxMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ extension FluxWorker where Self: FluxMiddleware {
/// - Parameter action: The type of the actions to associate with handler.
/// - Parameter compose: The closure that will be invoked when the action received.
public func registerComposer<Action: FluxAction>(for action: Action.Type, compose: @escaping (_ owner: Self, _ action: Action) -> FluxPassthroughAction) {
registerComposer(for: Action.self) { [unowned self] (action) -> FluxPassthroughAction in
registerComposer(for: Action.self) { [weak self] (action) -> FluxPassthroughAction in
guard let self = self else { return .next(action) }
return compose(self, action)
}
}
Expand All @@ -110,7 +111,8 @@ extension FluxWorker where Self: FluxMiddleware {
/// - Parameter action: The type of the actions to associate with handler.
/// - Parameter intercept: The closure that will be invoked when the action received.
public func registerInterceptor<Action: FluxAction>(for action: Action.Type, intercept: @escaping (_ owner: Self, _ action: Action) -> Void) {
registerComposer(for: Action.self) { [unowned self] (action) -> FluxPassthroughAction in
registerComposer(for: Action.self) { [weak self] (action) -> FluxPassthroughAction in
guard let self = self else { return .next(action) }
intercept(self, action)
return .stop()
}
Expand All @@ -120,7 +122,8 @@ extension FluxWorker where Self: FluxMiddleware {
/// - Parameter action: The type of the actions to associate with handler.
/// - Parameter execute: The closure that will be invoked when the action received.
public func registerHandler<Action: FluxAction>(for action: Action.Type, handle: @escaping (_ owner: Self, _ action: Action) -> Void) {
registerHandler(for: Action.self) { [unowned self] (action) -> Void in
registerHandler(for: Action.self) { [weak self] (action) -> Void in
guard let self = self else { return }
handle(self, action)
}
}
Expand Down

0 comments on commit 73e9a26

Please sign in to comment.