variables in SwiftUi to another Framework

Hallo I have a question. Is it possible that you can access a variable that you created in swiftui in other frameworks? In my case, for example, on the counter. Thanks in advance :)

import SwiftUI

import SpriteKit



class Gamescene: SKScene {

    

    

    

    var player = SKSpriteNode(color: .red, size: CGSize(width: 20, height: 20))

    

    override func sceneDidLoad() {

        

        player.position = CGPoint(x: size.width / 2, y: size.height / 2)

        

        addChild(player)

        

    }

}



struct ContentView: View {

    

    public var counter = 0.0

    

    var body: some View {

        SpriteView(scene: Gamescene(size: CGSize(width: 100, height: 150)))

            .ignoresSafeArea()

    }

}



struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}
Instance properties of a view is very private (adding public makes no sense) as the instance of the view is sort of temporal template which will be recreated at any time.

One way, is to declare the variable independently from the view and use it in the view and other frameworks.
Hard to say any details unless knowing how you want to use the variable.
I would like to use the Count variable to use a sprite note in the spritekit framework with the digital crown. At the moment I'm doing it via watchkit and I would be interested if it is even possible in swiftui.


class Gamescene: SKScene {

    

    

    

    var player = SKSpriteNode(color: .red, size: CGSize(width: 20, height: 20))

    

    override func sceneDidLoad() {

        

        player.position = CGPoint(x: size.width / 2, y: size.height / 2)

        

        addChild(player)

        

    }

}



struct ContentView: View {

    

    @State var counter = 0.0

    

    var body: some View {

        SpriteView(scene: Gamescene(size: CGSize(width: 100, height: 150)))

            .ignoresSafeArea()

            .focusable()

            .digitalCrownRotation($counter)

            

    }
Thanks for showing the new code. But there is still no code using counter.
variables in SwiftUi to another Framework
 
 
Q