Post

Replies

Boosts

Views

Activity

Sending Information From UIViewController To ContentView Every Frame
Context A SwiftUI app that uses the phone's camera to detect what hand sign I am doing in front of it and update a Text view in SwiftUI. The detection part is done in a UIViewController (primarily with Vision) and then that view is used in the main ContentView in SwiftUI. (UIViewControllerRepresentable) Problem I am able to print what hand sign I am doing in the front of the screen in the UIViewController, but not able to send that value to update the text label in SwiftUI. Here are my three main code files that pertain to this issue: ContentView.swift struct ContentView: View {       @State var text = ""       var body: some View {     ZStack {       Color(hex: "3E065F")         .ignoresSafeArea()       VStack {                   Text(text)           .foregroundColor(Color.white)           .font(.largeTitle)         MyCameraView(value: $text)       }     }   }     } MyCameraView.swift struct MyCameraView: UIViewControllerRepresentable {       @Binding var value: String   func makeUIViewController(context: Context) -> CameraViewController {     let cvc = CameraViewController()     return cvc   }   func updateUIViewController(     _ uiViewController: CameraViewController,     context: Context   ) {     value = uiViewController.currText // Only Called Once!   } } CameraViewController.swift final class CameraViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {    var currText = "A" ...    func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {     ...     guard let handSignsModel = try? VNCoreMLModel(for: SavedModel().model) else { print("Fail"); return }           let request = VNCoreMLRequest(model: handSignsModel) { (finishedRequest, err) in       guard let results = finishedRequest.results as? [VNClassificationObservation] else { return }       //print(results.first?.identifier)       self.currText = results.first!.identifier       print(self.currText)     }     try? VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: [:]).perform([request])   } } Please look at the print(self.currText) statement in the last file. I want to pass that value (every frame) to update the text in the ContentView. I tried to use updateUIViewController method in MyCameraView.swift, but it does not get called to update the text label every frame, only the first time it loads.
0
0
750
Nov ’21
How to transition from a SwiftUI Page to a SpriteKit Scene?
Hi, I am applying for this year's WWDC 2021 swift student challenge. I am creating a Mac Xcode Playground. I have created a start menu in Swift UI and a game in SpriteKit, I was wondering how I would go about transitioning between them when a button is clicked in the view. Right now I am using this code to display the SwiftUI view swift PlaygroundPage.current.setLiveView(   ContentView()     .frame(width: 800, height: 750) ) I was thinking I could transition like this: swift    func goToGameScene() {     let sceneView = SKView(frame: CGRect(x:0 , y:0, width: 800, height: 750))     if let scene = GameScene(fileNamed: "GameScene") {       sceneView.showsNodeCount = true       sceneView.showsFPS = true       scene.scaleMode = .aspectFit       sceneView.presentScene(scene)     }     PlaygroundPage.current.needsIndefiniteExecution = true     PlaygroundSupport.PlaygroundPage.current.liveView = sceneView   } I am not sure if this is a good approach. And this method does not give space for animated transitions as well. I was wondering if there is a better way to transition between these views, thank you so much in advance!
3
0
1.9k
Apr ’21
Which developer account to use for WWDC Swift Student Challenge?
Hello, I am a 14-year-old developer who wants to apply for the WWDC swift student challenge. My question is regarding the, "Be registered for free with Apple as an Apple developer or be a member of the Apple Developer Program", requirement. I use my dad's full developer account for publishing apps on the app store, but I also have a personal developer account. Which account should I use when applying. Please reply as soon as you can, thanks!
3
0
1.1k
Apr ’21