How to force a refresh of a SwiftUI View?

How to force a refresh of a SwiftUI View? Problem Description: I have a button with a .disabled() condition that’s a computed property of my ObservableObject model class. This means I can’t make it @Published. Something like this: class MyModel : ObservableObject { var isDisabled: Bool { if … { return true } else { … Read more

Only have one button active in dynamic list | SwiftUI

Only have one button active in dynamic list | SwiftUI Problem Description: I have a list generated from a ForEach loop: struct TrainingList: View { @EnvironmentObject var trainingVM: TrainingViewModel var body: some View { VStack(alignment: .leading) { Text("Your training sessions") .font(.system(size: 35, weight: .semibold, design: .default)) .padding(.all, 10) .foregroundColor(.white) Divider() ScrollView{ if(trainingVM.loading){ ProgressView("Loading training session").progressViewStyle(CircularProgressViewStyle(tint: … Read more

How does this function call this closure when each returns just a single Int?

How does this function call this closure when each returns just a single Int? Problem Description: I find this code very confusing: let myClosure = { (number1: Int, number2: Int) -> Int in return number1 * number2 } func useClosure(closure: (Int, Int) -> Int) { let result = closure(2, 3) print(result) // prints 6 } … Read more

Creating an Observable around an async/await method using RxSwift

Creating an Observable around an async/await method using RxSwift Problem Description: I am using the AWS Amplify library https://github.com/aws-amplify/amplify-swift to communicate with the Cognito service. Most of the functions have been rewritten using the new async/await approach. Looking at the following method: func fetchAuthSession() async throws -> AuthSession { return try await Amplify.Auth.fetchAuthSession() } How … Read more

We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject