UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: @EnvironmentObject @ObservedObject

Forums > SwiftUI

Hi everyone, I am totally a newbie here, I am probably making something very easy(ish) to be complicated

I am attempting to create a 10 Pin Bowling app, this will be able to record all scores, calculate handicaps etc, the part that I am totally confised abput is

I need 3 sliders (or 1 Struct) to be used 3 times called pin7, pin10 & pinStrike, I will need to use the desired results in several places (views) within the app, I am unable to make the selected values available elsewhere

Sorry for not supplying any code, it is just making me more confised looking at what I have already tried

I will be grateful for any help you guys can give me

2      

It seems like you jumped into the deep end of a swimming pool, and now are asking for swimming lessons?
Yet, at the other end of the pool, @twostraws has a 100 Day "how to swim" program. Did you take the lessons?

A great feature of these lessons is that he guides you in building applications. Several 100 Days of SwiftUI applications use the exact technique you're struggling with.

Here's one of his lessons that directly addresses your question: Sharing an Observed Object in a New View

If you are a total newbie, you may have problems understanding this lesson because it builds on the knowledge presented in previous lessons. If you're not familiar with those lessons, this one video will also be hard to understand.

I can't imagine outlining 5 or 7 steps to give you to solve your bowling pin problem. @twostraws has done a much better job at this over the span of a few weeks of course work. He only asks that you follow them in order, and you spend an hour or two each day working on the concepts.

Also, at the top of each page on the HWS website you'll see a search bar. Did you try it out? Give it a go! It's tuned to return videos and articles based on your search terms.

Additionally, many 100 Days of SwiftUI students have asked similar questions about observable objects, or environment objects here in these forum pages. Have you read any of the excellent responses? The answers you seek may already be available.

Please return here and let us know how you're progressing with 100 Days of SwiftUI. Share which videos you liked, and the specific parts of lessons that still confuse you. We're happy to help you. But maybe the deep end wasn't the place to start?

2      

Hi Obelix , thanks for you advice, and I will follow it

I have searched many places, but never seem to find the exact problem that I am facing, but that may be down to my understanding

I will be back to let you knowe how I get on

2      

Hi I have made it to day 17, and it 's finally clicked

An example og my test code :

struct ContentView: View {
    @StateObject var board = BoardToUse()

    var body: some View {
        VStack {
            Text("Pin 7 Board \(board.pin, specifier: "%.2f") ContentView")
                .padding()
            PinSlider(board: board.self)
        }
    }
}

struct PinSlider: View {
    @ObservedObject var board: BoardToUse

    var body: some View {
        VStack {
            Text("Pin 7 Board \(board.pin, specifier: "%.2f") Slider view")
            Slider(value: $board.pin, in: 1...39, step: 0.25)
        }
    }
}

class BoardToUse: ObservableObject {
    @Published var pin:Double = 20
}

Thanks for your training Paul, it is by far the best that I have seen, maybe time to put your dogs in the credits :)

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.