Post

Replies

Boosts

Views

Activity

Reply to NavigationSplitView hide sidebar toggle button
You can use the toolbar(_:for:) modifier on your sidebar view like this: .toolbar(.hidden, for: .navigationBar). You can find details in the documentation here. Here's the resulting view: struct SomeView: View { var body: some View { NavigationSplitView( columnVisibility: .constant(.all), sidebar: { Text("sidebar") .toolbar(.hidden, for: .navigationBar) }, detail: { Text("detail") } ) .navigationSplitViewStyle(.balanced) } } The first argument sets the visibility, and the second arguments specifies which bar to hide (which in your case is .navigationBar).
Apr ’23
Reply to Add resources in Swift Playgrounds 4
The Resources folder should be automatically created when you add a resource file such as a sound file, or a CoreML model, and you don't need to modify the Package.swift file. To add files to your Resources folder, you can drag and drop them or go to File > Add File, and select your resource. If your question is how to add another folder that works as a resource folder, you can add it in the resources part of Package.swift like this: targets: [ .executableTarget( name: "AppModule", path: ".", resources: [ .process("Resources"), /* don't forget the comma */ .process("OtherFolder") // the folder you want to add as a resources folder (replace OtherFolder with the desired name) ] ) ] If you're asking how to edit the Package.swift file, I'm not sure if you can open it in Playgrounds. On macOS, you can right click on the App Playground > Show In Finder to get to its location, and then right click > show contents on the app to see the its files, including the Package.swift file. To use your resource files, you need to use something like let url = Bundle.main.url(forResource: "ResourceFile", withExtension: "txt") in combination with something else, depending on what you want to use it for.
Apr ’23
Reply to iOS 17 Features being depreciated
Hi! It seems that App Playgrounds require support for iOS 16.0 on this version of Xcode (not sure if this is a bug or intended for compatibility reasons). Even though you want to run your app on an iOS 17.0 device, the App Playground is set to build for iOS 16 devices too, and this is why your build fails (remember, to run a code it must first be built, and building requires your code to work on all devices it is configured for, not just on the one you use to test it). You should've received some relevant error messages and fixes that mention the if #available version check or the @available(iOS 17.0, *) attribute. These may be useful If you want to maintain the iOS 16 compatibility. This is analogous to changing the minimum iOS deployment version in an .xcodeproj. You could use the if #available version check like this: import SwiftUI struct ContentView: View { var body: some View { VStack { if #available(iOS 17.0, *) { ScrollView { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("iOS 17.0") } .defaultScrollAnchor(.bottom) } else { ScrollView { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("iOS 16.0") } } } } } Or you could add the @available(iOS 17.0, *) attribute to the enclosing View like this: import SwiftUI @available(iOS 17.0, *) struct ContentView: View { var body: some View { VStack { ScrollView { Image(systemName: "globe") .imageScale(.large) .foregroundColor(.accentColor) Text("Hello, world!") } .defaultScrollAnchor(.bottom) } } } And then, in the App struct, use the if #available version check: import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { if #available(iOS 17.0, *) { ContentView() } else { // Fallback on earlier versions Text("This feature requires iOS 17.0.") } } } } Now, if you want a "hacky" method, you could edit the package files of your App Playground. To do this, go to File > Show in Finder, and then open the Package.swift file. After that, you can change the .iOS("16.0") line to 17.0. Also, I recommend you to use the latest Xcode version & macOS (they bring bug fixes and security improvements 😁). Good luck and Happy New Year!
Jan ’24
Reply to An error appears (Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value) when I try to add a scene file with the .sks extension to an app playground type project with the .swiftpm extension
Hi and happy new year! The error indicates that the file wasn't found - the app usually searches the file inside the Resources folder. I am not sure if moving it inside the Resources folder inside GamePlayground would work. If it doesn't, try adding the scene again so that a "global" Resources folder is created (either drag & drop the scene or click the plus button in the bottom left.
Jan ’24