From 72cf825cead54d1d1552f44f1220af4216427df2 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 19 Apr 2021 16:28:17 +0100 Subject: [PATCH 1/2] Clarify docs for UIKit --- Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift b/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift index 744b16b64a52..c4dafe8b633a 100644 --- a/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift +++ b/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift @@ -4,6 +4,9 @@ extension Store { /// Subscribes to updates when a store containing optional state goes from `nil` to non-`nil` or /// non-`nil` to `nil`. /// + /// **NOTE:** one of the `unwrap` or `else` closures is always called based on the *initial* state of the + /// optional state (`nil` or non-`nil`), in addition to subsequent changes of `nil` / non-`nil`. + /// /// This is useful for handling navigation in UIKit. The state for a screen that you want to /// navigate to can be held as an optional value in the parent, and when that value switches /// from `nil` to non-`nil` you want to trigger a navigation and hand the detail view a `Store` @@ -35,9 +38,10 @@ extension Store { /// /// - Parameters: /// - unwrap: A function that is called with a store of non-optional state whenever the store's - /// optional state goes from `nil` to non-`nil`. - /// - else: A function that is called whenever the store's optional state goes from non-`nil` to - /// `nil`. + /// optional state is initially non-`nil` or goes from `nil` to non-`nil`. + /// - else: A function that is called whenever the store's optional state is initially `nil` or + /// goes from non-`nil` to `nil`. + /// - Returns: A cancellable associated with the underlying subscription. public func ifLet( then unwrap: @escaping (Store) -> Void, From ec0c6bf67f951f10e31b4543aabbdf0a2ccc158e Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 19 Apr 2021 16:32:44 +0100 Subject: [PATCH 2/2] Add clarification to override also --- Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift b/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift index c4dafe8b633a..10d1a2b69889 100644 --- a/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift +++ b/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift @@ -80,7 +80,7 @@ extension Store { /// case. /// /// - Parameter unwrap: A function that is called with a store of non-optional state whenever the - /// store's optional state goes from `nil` to non-`nil`. + /// store's optional state is initially non-`nil` or goes from `nil` to non-`nil`. /// - Returns: A cancellable associated with the underlying subscription. public func ifLet( then unwrap: @escaping (Store) -> Void