salferrari
salferrari

Reputation: 81

How can I target a SwiftUI app for Apple TV

I'm creating an app in SwiftUI. I have it running on Mac and iOS.

How do I get it to run on my Apple TV?

I've never developed for Apple TV before. Can I run the existing app and see what it looks like on the TV. Thanks for any tips you can share.

Upvotes: 3

Views: 1327

Answers (1)

Jeff
Jeff

Reputation: 891

The first step is to add a new target for tvos. In your project settings click the + button under targets, then select the tvos tab, and choose Single View App.

Finish creating the target, make sure you select SwiftUI for the user interface.

You should have a new tvos folder under your project, go to AppDelegate.swift and change the UIHostingController to point to your main SwiftUI view.

window.rootViewController = UIHostingController(rootView: YourMainView())

You may need to go to your swift source files and check that the target membership includes tvos

Target Membership

Change your run target to tvos, and click run.

enter image description here

You will probably have to do some work to support the tvos platform in your app, some of the swiftUI user input events are pretty different in tvos.

Upvotes: 2

Related Questions