TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Inject GKMatch into SwiftUI

Forums > SwiftUI

How do I inject GKMatch into SwiftUI view similar to this example https://www.hackingwithswift.com/books/ios-swiftui/using-coordinators-to-manage-swiftui-view-controllers ? I am building a multiplayer game in SwiftUI and I had to use UIViewControllerRepresentable to wrap the GKMatchMakerViewController into SwiftUI, however, I face a little problem where GKMatchDelegate methods are not being called. I have detected that it is happening because I dismiss the viewcontroller on didFindMatch method. I have tried to follow the above linked example, but I am not sure how I can put the GKMatch into a SwiftUI view as twoStraws did with the image in the example like so

func loadImage() {
    guard let inputImage = inputImage else { return }
    image = Image(uiImage: inputImage)
}

Can someone tell me what I can do? I tried my version like below.

func loadMatch() {
        guard let uImultiPlayerMatch = uImultiPlayerMatch else { return }
        multiPlayerMatch = uImultiPlayerMatch
    }

This is the code I have to load the GKMatch: multiPlayerMatch into my view but it doesn't solve my problem. Which view can take in the GKMatch type?

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your 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.