Block rotation & fix landscape for .swiftpm

Greetings, I want to force my app's Orientation. Most solutions for "How to force orientation to Landscape for SwiftUI" seems works only for "real" SwiftUI project, not .swiftpm

How can I force orientation to landscape for Swift Playground App Project?

Answered by chewethan in 710767022

You can open 'Package.swift' and under supportedInterfaceOrientations which should be

 supportedInterfaceOrientations: [
                .portrait,
                .landscapeRight,
                .landscapeLeft,
                .portraitUpsideDown(.when(deviceFamilies: [.pad]))
]

remove .portrait' and '.portraitUpsideDown(.when(deviceFamilies: [.pad])), and therefore the final code should be

 supportedInterfaceOrientations: [
                .landscapeRight,
                .landscapeLeft,
]

Hope that helped!

Accepted Answer

You can open 'Package.swift' and under supportedInterfaceOrientations which should be

 supportedInterfaceOrientations: [
                .portrait,
                .landscapeRight,
                .landscapeLeft,
                .portraitUpsideDown(.when(deviceFamilies: [.pad]))
]

remove .portrait' and '.portraitUpsideDown(.when(deviceFamilies: [.pad])), and therefore the final code should be

 supportedInterfaceOrientations: [
                .landscapeRight,
                .landscapeLeft,
]

Hope that helped!

I may add few details about this 'cause it's been a trouble for some days and I want to share my experience that might help others:

  • The Package.swift file will not show up in Playground App neither in Xcode project Navigator. It is an automatic file that appears inside the package content if you go in finder and with the right click go to "Show Package Content". Beware of modifying it if you don't know what to write as it could mess up your project. Also you have to be on macOS to do it, on iPad I could not.

  • If you're using version control for the swiftpm, the Package file will not update with commit, so even if you modify and then share it on your iPad for opening in Playground, your app will still rotate and perhaps other things might be missing.

All other threads point to this answer so I apologise if that's not the appropriate place to write.

Block rotation & fix landscape for .swiftpm
 
 
Q