Skip to content

Commit ba2b9e0

Browse files
authored
Clarify docs for UIKit ifLet function (#497)
* Clarify docs for UIKit * Add clarification to override also
1 parent 4ea3dfe commit ba2b9e0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ extension Store {
44
/// Subscribes to updates when a store containing optional state goes from `nil` to non-`nil` or
55
/// non-`nil` to `nil`.
66
///
7+
/// **NOTE:** one of the `unwrap` or `else` closures is always called based on the *initial* state of the
8+
/// optional state (`nil` or non-`nil`), in addition to subsequent changes of `nil` / non-`nil`.
9+
///
710
/// This is useful for handling navigation in UIKit. The state for a screen that you want to
811
/// navigate to can be held as an optional value in the parent, and when that value switches
912
/// from `nil` to non-`nil` you want to trigger a navigation and hand the detail view a `Store`
@@ -35,9 +38,10 @@ extension Store {
3538
///
3639
/// - Parameters:
3740
/// - unwrap: A function that is called with a store of non-optional state whenever the store's
38-
/// optional state goes from `nil` to non-`nil`.
39-
/// - else: A function that is called whenever the store's optional state goes from non-`nil` to
40-
/// `nil`.
41+
/// optional state is initially non-`nil` or goes from `nil` to non-`nil`.
42+
/// - else: A function that is called whenever the store's optional state is initially `nil` or
43+
/// goes from non-`nil` to `nil`.
44+
4145
/// - Returns: A cancellable associated with the underlying subscription.
4246
public func ifLet<Wrapped>(
4347
then unwrap: @escaping (Store<Wrapped, Action>) -> Void,
@@ -76,7 +80,7 @@ extension Store {
7680
/// case.
7781
///
7882
/// - Parameter unwrap: A function that is called with a store of non-optional state whenever the
79-
/// store's optional state goes from `nil` to non-`nil`.
83+
/// store's optional state is initially non-`nil` or goes from `nil` to non-`nil`.
8084
/// - Returns: A cancellable associated with the underlying subscription.
8185
public func ifLet<Wrapped>(
8286
then unwrap: @escaping (Store<Wrapped, Action>) -> Void

0 commit comments

Comments
 (0)