Skip to content
0:00 / 0:00

#swiftui#swift#statemanagement

SwiftUI Tutorial: What's the difference between @State, @ObjectBinding, and @EnvironmentObject?

Paul Hudson

122K subscribers • 15 videos on Hallway

YouTube
  • Recommended by 3 people: 3 in engineering communities.
  • Presented by Paul Hudson
  • May be out of date. The tools, versions or practices it shows have likely moved on.

Intermediate. Assumes working knowledge.

133K views7 years ago3 recommendations

Mobile developmentSoftware designiOS and SwiftUIFlutter and React NativeDesign patterns

Paul Hudson explains the differences between SwiftUI's state management options with hands-on code examples.

If you want to understand how SwiftUI works with state, start here – this video walks you through how state works, why it matters, and how each of SwiftUI's state options work, all using hands-on code examples so you can see for yourself. For more information on SwiftUI, see my free online book SwiftUI By Example: hackingwithswift.com/quick-start/swiftui/

Why it's here

3 people recommend this

What people say. Recommended as a clear explanation of state management and data flow in SwiftUI.

Moments people linked to

u/PrayForTechin r/swift • Recommends

On “What’s everyone working on this month? (March 2020)”

Use a class conforming to Observable Object protocol - classes’ data is available all views. So if you have a Currency class, in ContentView: View, you could do var currency = Currency(). In addition, you could make it into an EnvironmentObject; watch this video that’ll explain this in more detail.

u/trusk89in r/swift • Recommends

On “Passing closures between SwiftUI sibling views (and UIViewRepresentables)”

Well, the hardest part in learning SwiftUI is actually learning Combine, the states and single source of truth concept. Hacking with swift has some really good explained videos link to this video
2View on Reddit

u/trusk89in r/swift • Recommends

On “Passing closures between SwiftUI sibling views (and UIViewRepresentables)”

This is a video I like link to this video

u/Lygrein r/swift • Recommends

On “How to Call Code From Subview Back to Superview (SwiftUI)”

Instantz is correct, based on your description. Here is a video by Paul Hudson that explains it really nicely What you’re wanting to do, in swiftUI needs a property wrapper, and a publisher, but @State bakes it all together nicely for us without the overhead. You can make your own custom ones however, and use the .onRecieve modifier to get the published event