1

Prior to iOS 14 my project was working fine with the following code

struct LoginView: View, Resolving {

    @ObservedObject var loginUIService: LoginUIService = Resolver.resolve()
    ...
    var body: some View {
        ...
        TextField(LocalizedString.Placeholder.email.localized, text: self.$loginUIService.loginViewModel.emailAddress)
        ...
    }
}

This is my partial service class

class LoginUIService: ObservableObject, Resolving {
    
    @Published var loginViewModel: LoginViewModel = Resolver.resolve()
    ...
}

And then the view model

class LoginViewModel: ObservableObject {
    
    
    //MARK:- Properties
    @Published var emailAddress: String {
        didSet {
            checkIsValid()
        }
    }
    @Published var password: String{
        didSet {
            checkIsValid()
        }
    }
    @Published var isValid = false

    
    //MARK:- Init Methods
    init() {
        emailAddress = ""
        password = ""
    }
    
    init(emailAddress: String, password: String) {
        self.emailAddress = emailAddress
        self.password = password
    }
    
    fileprivate func checkIsValid() {
        isValid = emailAddress.isEmpty == false && password.isEmpty == false && emailAddress.contains("@")
    }
    
}

In iOS 13 this code all works 100% without any issues and now when running on an iOS14 device I am getting the following output in the console when tapping on the textfields

Binding<String>(transaction: SwiftUI.Transaction(plist: []), location: SwiftUI.LocationBox<SwiftUI.(unknown context at $7fff562e301c).ProjectedLocation<SwiftUI.LocationBox<SwiftUI.ObservableObjectLocation<Recon.LoginUIService, Recon.LoginViewModel>>, Swift.WritableKeyPath<Recon.LoginViewModel, Swift.String>>>, _value: "")

Has anyone experience this issue recently ?

BrettS
  • 295
  • 6
  • 14
  • I cannot agree that `self.$loginUIService.loginViewModel.emailAddress` is a valid usage of `ObservedObject` binding... so would never recommend to use it that way. – Asperi Oct 08 '20 at 14:27
  • I'm experiencing this issue. I'm currently submitting a bug report to Apple. I am using two separate TextFields with a single string binding. When I edit the text from the binding and the second TextField, it appears to throw this exception. I imagine something is causing the second TextField to redraw, which causes it to lose its binding transaction scope. I'll report back if I find out the root cause. – Tom GODDARD Nov 23 '20 at 01:17

0 Answers0