Skip to content

Pass UIApplication.OpenURLOptionsKey in action from AppDelegate. #1580

Answered by tgrapperon
asa08 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @asa08! You can put this dictionary beside the URL in openUrl. But doing so prevents automatic Equatable synthesis for your Action. One way to do this while keeping your Action Equatable for testing is to create a wrapper type:

public struct OpenUrlRequest: Equatable {
  let url: URL
  let options: [UIApplication.OpenURLOptionsKey: Any]
 
  public static func == (lhs: Self, rhs: Self) -> Bool { lhs.url == rhs.url }
}

and you can refactor openUrl(URL) into openUrl(OpenUrlRequest), so you can send:

viewstore.send(.openUrl(.init(url: url, options: options)))

The sub-optimal Equatable conformance will weaken your tests, but it should be relatively OK.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@asa08
Comment options

Answer selected by asa08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants