0

error code snippetI need to initialize an Observed object in SwiftUI, but when i put “@ObservedObject var progress: UserProgress” it provokes an error as you can see on the photo. The error says “Return from initializer without initializing all stored properties”. What should I add to the following block of code to make it work ? Thank you in advance!

@ObservedObject var progress: UserProgress
    init(selectedTab: Binding<String>) {
        self._selectedTab = selectedTab
        UITabBar.appearance().isHidden = true
    }

I don't understand what should I put in init(selectedTab: Binding)

Tomas
  • 1
  • You're getting that error because you haven't set anything for `progress` yet. It's unclear from your code what you _should_ set it to. However, you shouldn't be using `@ObservedObject` where you _own_ an object -- you should be using `@StateObject`. Regarding initializing in `init`, see https://stackoverflow.com/questions/62635914/initialize-stateobject-with-a-parameter-in-swiftui – jnpdx Jul 25 '23 at 21:37

0 Answers0