Pass UIApplication.OpenURLOptionsKey in action from AppDelegate. #1580
-
I want to pass UIApplication.OpenURLOptionsKey from AppDelegate by action. AppDelegate func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
viewStore.send(.openUrl(url: url))
} Core extension AppDelegateCore {
struct Environment {
var twitterClient: TwitterClient
}
}
extension AppDelegateCore {
static let reducer = Reducer<State, Action, Environment>.combine(
.init { state, action, environment in
switch action {
case .openUrl(let url):
// To give it here
let result = environment.twitterClient.application(url: url, option: ## OPTION ##)
...
}
}
)
} TwitterClient import TwitterKit
protocol TwitterClient {
func application(url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool
}
final class TwitterClientImpl: TwitterClient {
func auth(url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
TWTRTwitter.sharedInstance().application(UIApplication.shared, open: url, options: options)
}
} Thanks for looking. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @asa08! You can put this dictionary beside the 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 viewstore.send(.openUrl(.init(url: url, options: options))) The sub-optimal |
Beta Was this translation helpful? Give feedback.
Hey @asa08! You can put this dictionary beside the
URL
inopenUrl
. But doing so prevents automaticEquatable
synthesis for yourAction
. One way to do this while keeping yourAction
Equatable
for testing is to create a wrapper type:and you can refactor
openUrl(URL)
intoopenUrl(OpenUrlRequest)
, so you can send:The sub-optimal
Equatable
conformance will weaken your tests, but it should be relatively OK.