Search results for

[tags:wwdc20-10106]

24 results found

Post

Replies

Boosts

Views

Activity

SwiftUI Scene with a single window on macOS
Is it possible to only allow a single window instance on macOS? WindowGroup/DocumentGroup allow the user to create multiple instances of a window. I'd like to only allow one, for an Onboarding sequence. I've checked the Scene documentation - https://developer.apple.com/documentation/swiftui/scene, and it appears the only types conforming to the Scene protocol are WindowGroup, DocumentGroup and Settings. How can I create a single Window in a SwiftUI App? An example use case: struct TutorialScene: Scene { var body: some Scene { t// I don't want to allow multiple windows of this Scene! tWindowGroup { ttTutorialView() t}t }
6
0
5.1k
Jul ’24
SwiftUI Toolbar back button on macOS
I have a layout similar to Music or Podcasts, where I have a sidebar and a grid content area. When clicking on one of the items in the grid I want to open a full screen detail view just like Music does. My question is: How can I display a back button in the toolbar? I only figured out how to add buttons to the trailing side of the toolbar. Is this even possible in pure SwiftUI? .toolbar { Button(action: showSearch) { Label(Add Game, systemImage: plus) } }
2
0
4.4k
Dec ’20
@FocusedBinding
Hello, During the talk there is a sample code using new property wrapper @FocusedBinding. Can you expand more on this topic with small example how to use this new property wrapper, there has been clear examples of @AppStorage, @StateObject, @SceneStorage however no talk expands more on @FocusedBinding. The documentation is not very clear neither. Thank you.
12
0
6.3k
Dec ’20
How to conditionally show a SwiftUI Scene on macOS?
I have an Onboarding Window/Scene I want to appear on the first launch of the app, or when a use clicks a menu command. Using an AppStorage with a boolean value would be perfect, but when I try to add an if in my SceneBuilder I get the following error: Closure containing control flow statement cannot be used with function builder 'SceneBuilder'. import SwiftUI @main struct MyApp: App { @AppStorage(tutorialVisible) var tutorialVisible: Bool = true var body: some Scene { MainScene() if tutorialVisible { TutorialScene() } } } How can this be done?
4
0
5.4k
Dec ’20
How do I get my WatchOS target to use the Shared folder in Multi Platform Template?
Hi everyone, When I add WatchOS as a target to my multi platform SwiftUI project, it creates its own ContentView within the Watchkit Extension folder. It does not seem to be able to access any views within the Shared folder in the multi platform App template, leaving me with two Content Views in the project. Does anyone know how to add a WatchOS target and have it use the shared files? Can this be done? I was encouraged because the App Essentials WWDC20 video implies WatchOS can be used with this template as they have a screenshot example, but so far haven't had success in duplicating it.
2
0
4.3k
Nov ’20
onDeleteCommand modifier
Has anyone had success getting the .onDeleteCommand() modifier to work with a List? .Delete() seems to be working fine, and enables swipe-to-delete on any platform, and I figured the onDeleteCommand modifier was the key to enabling the Edit > Delete menu on macOS, but no matter where I put the modifier in my view the Edit > Delete command remains disabled.
1
0
2.0k
Sep ’20
How to Instantiate UIHostingController with CoreData??
As a long-time Obj-C dev (since iPhone OS 2) I decided that SwiftUI was the nudge to use Swift! ¯_(ツ)_/¯ Thus, I am still trying to understand how a language can be so type-vague in code, and so type-pedantic in the compiler!!! Pulling my hair out trying to get Swift/SwiftUI to instantiate a UIHostingController<>, for use with CoreData class MyCoreDataHostingController : UIHostingController { required init?(coder: NSCoder) {//Instantiate From Storyboard let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext let contentView = MyCoreDataView().environment(.managedObjectContext, context) super.init(coder: coder, rootView: contentView) //Cannot convert value of type 'some View' to expected argument type 'MyCoreDataView' } } struct MyCoreDataView: View { var body: some View { Text(Core Data View) } } How can I FORCE Swift to INFER the correct/appropriate type? What I have tried so far. 5 let contentView = MyCoreDataView() Compiles/runs, but does not include CoreData. 6
2
0
1.7k
Aug ’20
How to create different scenes with different views by code?
WWDC2020 videos said SwiftUI on Xcode12 can create and manage different scenes in an App, but we do not find out any API could do that. We try the method of SwiftUI on Xcode11 to create new Window on Xcode 12 : UIApplication.shared.requestSceneSessionActivation(nil, userActivity: nil, options: nil, errorHandler: nil) }) But it does not work as we expect. The code create a window of the same scene. If we set a different userActivity, SwiftUI have no method to set SceneDelegate.swift. It only has @UIApplicationDelegateAdaptor to set AppDelegate. So, I Wonder whether there is a convenient way to create a new Scene by new SwiftUI APIs. The following code can only create Scenes with the same content view : @main struct test: App { let newWindowPublisher = NotificationCenter.default.publisher(for: Notification.Name(anotherScene)) var body: some Scene { WindowGroup { ContentView() .onReceive(newWindowPublish, perform: { info in UIApplication.shared.requestSceneSessionActivation(nil, userActivity: nil, options: nil,
1
0
3.8k
Aug ’20
Creating NSPresistantContainer in Appdelegate / scene builder
With the recent changes to allow for an app to be completely in SwiftUI, I am trying to re-create a simple core data and SwiftUI app. How can a NSPresistantContainer be setup with the new app delegate adaptor and scene builder? I have attempted what has worked previously by creating a lazy var in the app delegate and then providing that as an adaptor on the app struct. What is the correct way to setup the NSPresistantContainer so the NSManagedObjectModel is loaded? class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if isDataSet() == false { setDefaultData() } return true } lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: breakapp) container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError(Unresolved error (error), (error.userInfo)) } }) return cont
2
0
1.9k
Aug ’20
How to handle URL callbacks with new SwiftUI @main startup?
In the old SwiftUI app initialization there was UIApplicationDelegate and UIWindowSceneDelegate. I was handling a URL callback in the SceneDelegate using the method: func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) However in the new app initialization there is no SceneDelegate, nor an appropriate property like there is UIApplicationDelegateAdaptor for UIApplicationDelegate I tried using the method but it is not called. func application( _ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool So my question is, how do I handle a callback url in the new app setup?
4
0
10k
Jul ’20
State in the Interface
In the session App essentials in SwiftUI around minute 8, the presenter is showing how switching between app windows does not affect the selection state. This works really well. The problem as you can see on the video is that the selection on the list don't persist. If you look closely every time he switches between apps the list is now unselected. I tried solving this problem using @SceneStorage property wrapper - as suggested - but that didn't work.
1
0
352
Jul ’20