WWDC21 SALE: Save 50% on all my Swift books and bundles! >>

Inquiry regarding SwiftUI and SpriteKit Integration

Forums > SwiftUI

I've been playing with the demo presented in "How to integrate SpriteKit using SpriteView" (https://www.hackingwithswift.com/quick-start/swiftui/how-to-integrate-spritekit-using-spriteview) in which didTouch spawns SKNodes of red boxes. I was wondering how one would go about dynamically displaying the number of boxes back in ContentView. I've tried making GameScene and ObservableObject and using @Published to send the value back to @StateObject in ContentView. But that doesn't work. Any suggestions will be appreciated!


I have the same issue. Stated a slightly different way: I keep state in a @EnvironmentObject var appState. I want access to appState inside the SKScene.


Save money with our WWDC sale!

SAVE 50% To celebrate WWDC21, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

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.