Monday, August 15, 2022
HomeiOS Developmentios - Utilizing @FocusState on a TextField inflicting reminiscence leaks

ios – Utilizing @FocusState on a TextField inflicting reminiscence leaks

[ad_1]

I’m studying reminiscence and ARC since some time and managed to make use of the Leaks instrument extra typically with a purpose to produce high quality code. Having that stated, please take into account my lack of expertise on this zone.

Drawback: I constructed a mum or dad view A that presents a view B.

B comprises a login type constructed utilizing a TextField, a SecureField and a Button. I even have a @FocusState personal var isFocused: Bool property that helps me conceal the keyboard with a purpose to bypass the “AttributeGraph: cycle detected” console error that exhibits up as soon as I disable the textfield on button press having the keyboard on display. (Get `AttributeGraph: cycle detected` error when altering disabled state of textual content area)

I observed that after I use the @FocusState property, as soon as I dismiss B, the Leaks instrument detects two “Malloc 32 Bytes” leaks identical to within the image beneath.

If I do not use the @FocusState property, the leaks will now not present up. Am I doing one thing incorrect or is that this some sort of bug / false optimistic from Swift?

enter image description here

This view is partially extracted from my file so it does not have all it is properties and strategies right here.

struct AuthenticationLoginView: View {
       
    @StateObject var viewModel = AuthenticationLoginViewModel()
    
    @FocusState personal var isFocused: Bool
    
    var physique: some View {
            VStack {
                TextField(textual content: $viewModel.username) {
                    Textual content("placeholder.")
                }
                .tag(AuthenticationLoginField.username)
                .textInputAutocapitalization(.by no means)
                .centered($isFocused)
                .disabled(viewModel.isLoggingIn)
                SecureField(textual content: $viewModel.password) {
                    Textual content("Password")
                }
//                .centered($isFocused)
                .disabled(viewModel.isLoggingIn)
                .tag(AuthenticationLoginField.password)
            }
    }
}

[ad_2]

RELATED ARTICLES

Most Popular

Recent Comments