You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to integrate TCA into a project that used the UIKit lifecycle, and I'm changing it to SwiftUI with TCA. The project is quite a mess, and I'm new to TCA. There is a REST service that accepts requests from Providers signs them with a token stored Session singleton, and returns data from the executed request. However, when the request returns HTTP Error 4xx, it calls a function on the Session and the user is logged out. The Session also has a function var onSignOut: (() -> Void)? that is implemented in the UINavigationController class. The function switches the current screen to login.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to integrate TCA into a project that used the UIKit lifecycle, and I'm changing it to SwiftUI with TCA. The project is quite a mess, and I'm new to TCA. There is a
RESTservice that accepts requests fromProviderssigns them with a token storedSessionsingleton, and returns data from the executed request. However, when the request returns HTTP Error 4xx, it calls a function on theSessionand the user is logged out. TheSessionalso has a functionvar onSignOut: (() -> Void)?that is implemented in theUINavigationControllerclass. The function switches the current screen to login.How would I go about this in TCA?
The code essentialy looks like this
SomeProvider.swift
// Provider let response: Data = try await rest.perform(request: request)REST.swift
// REST performs the request Session.shared.react(to: response.statusCode)Session.swift
// Session reacts func react(to statusCode: Int) { if statusCode >= 400, statusCode < 500 { signOut() } } // Session signs user out. func signOut() { token = nil onSignOut?() }iOS 16
Beta Was this translation helpful? Give feedback.
All reactions