What's new in SwiftUI

RSS for tag

Discuss the WWDC23 Session What's new in SwiftUI

Posts under wwdc2023-10148 tag

7 Posts

Post

Replies

Boosts

Views

Activity

Screen flickering issue with full with xcode 15 and macOS Sonoma
my Mac is M1 Pro 2021 , I recently updated to macOS Sonoma and it was fine, of course a lot of softwares weren't working but it's common right? But when I am opening canvus in Xcode 15 and working in it , my mac's screen started blinking crazy that I can't use it now and the mac was freeze and need to shut down . . Is it just me?
4
1
2.3k
Oct ’23
NavigationSplitView crashes in Xcode, iOS Beta 7
I have a NavigationSplitView with a sidebar. When selecting a new item on the sidebar, the app crashes. The error message says: Simultaneous accesses to 0x6000030107f0, but modification requires exclusive access. Xcode shows that the crash occurs inside the generated code in my class with @Observable macro. @ObservationIgnored private let _$observationRegistrar = Observation.ObservationRegistrar() internal nonisolated func access<Member>( keyPath: KeyPath<NavModel , Member> ) { _$observationRegistrar.access(self, keyPath: keyPath) } internal nonisolated func withMutation<Member, MutationResult>( keyPath: KeyPath<NavModel , Member>, _ mutation: () throws -> MutationResult ) rethrows -> MutationResult { // Crash occurs on the following line try _$observationRegistrar.withMutation(of: self, keyPath: keyPath, mutation) } @ObservationIgnored private var _section: SidebarSection? = .one To reproduce the crash, I tap a new item on the sidebar until the app crashes. It usually only takes 1-3 times selecting a new item before the crash occurs. Below is the code for an entire app to reproduce the crash. Has anyone else encountered this issue? Thank you! import SwiftUI @main struct NavigationBugApp: App { var body: some Scene { WindowGroup { ContentView() } } } @Observable class NavModel { var section: SidebarSection? = .one } enum SidebarSection: Hashable { case one case two } struct ContentView: View { @State private var model = NavModel() var body: some View { NavigationSplitView { List(selection: $model.section) { NavigationLink("One", value: SidebarSection.one) NavigationLink("Two", value: SidebarSection.two) } .listStyle(.sidebar) } detail: { Text("Hello World") } } } #Preview { ContentView() }
2
0
1.4k
Aug ’23
Using SettingsLink from MenuBarExtra does not activate the app
I have a Utility app that does not have a Dock icon and runs in the menu bar. On macOS Sonoma (14 DB 1) you cannot use anymore the workaround that we used on previous versions of the macOS, as you get a warning that you should use SettingsLink. NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil) But the issue is, that before I usually were calling as well NSApp.activate(ignoringOtherApps: true) to activate the app. As clicking on the MenuBar app icon does not do that. The SettingsLink only opens the Settings Scene, but does not actually activates the app. I could not find a workaround how to do so. As I cannot inject my code in SettingsLink call. Any ideas how I can activate my app when SettingsLink is called?
1
2
1.8k
Jul ’23
Why don't interactive buttons in iOS 17 widget call AppIntent perform() when the app running?
Inside a widget, there is a button, Button(intent: AnAppIntent()) { // Button's label. } // It seems this modifier does not add any value. .invalidatableContent() connected to an AppIntent. struct AnAppIntent: AppIntent { static var title: LocalizedStringResource = "An AppIntent" init() { // AppIntent required init. } func perform() async throws -> some IntentResult { // Never called when the app is running. return .result() } } The button calls AppIntent's perform() when tapped, and it consequently updates the widget UI (with or without the modifier .invalidatableContent()) only when the app is closed completely. If the app is alive in the background, perform() is not called, and the widget UI never updates. The user must explicitly dismiss the app to make the widget work as expected. The problem may be in the timeline used. struct SimpleEntry: TimelineEntry { let date: Date } struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) } func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { completion(SimpleEntry(date: Date())) } func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { var entries: [SimpleEntry] = [] // Generate a timeline of five entries an hour apart, starting from the current date. let currentDate = Date() for hourOffset in 0 ..< 5 { let entryDate = Calendar.current.date(byAdding: .second, value: hourOffset, to: currentDate)! entries.append(SimpleEntry(date: entryDate)) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } } However, if the problem were the timeline, the widget would not work with the app dismissed. Any idea on how to keep interactive widgets always working?
2
1
3.1k
Jun ’23
Customize DocumentGroup in SwiftUI with SwiftData
How do I customize my app's startup experience when using DocumentGroup in SwiftUI with SwiftData? I don't want my users to be greeted with a document browser on startup. Rather, I want to offer an experience like PhotoShop where the user is greeted by an "empty" version of my app's editor view. They can then use something like File->New or File->Open to get started.
1
1
1.2k
Jun ’23
Screen flickering issue with full with xcode 15 and macOS Sonoma
my Mac is M1 Pro 2021 , I recently updated to macOS Sonoma and it was fine, of course a lot of softwares weren't working but it's common right? But when I am opening canvus in Xcode 15 and working in it , my mac's screen started blinking crazy that I can't use it now and the mac was freeze and need to shut down . . Is it just me?
Replies
4
Boosts
1
Views
2.3k
Activity
Oct ’23
NavigationSplitView crashes in Xcode, iOS Beta 7
I have a NavigationSplitView with a sidebar. When selecting a new item on the sidebar, the app crashes. The error message says: Simultaneous accesses to 0x6000030107f0, but modification requires exclusive access. Xcode shows that the crash occurs inside the generated code in my class with @Observable macro. @ObservationIgnored private let _$observationRegistrar = Observation.ObservationRegistrar() internal nonisolated func access<Member>( keyPath: KeyPath<NavModel , Member> ) { _$observationRegistrar.access(self, keyPath: keyPath) } internal nonisolated func withMutation<Member, MutationResult>( keyPath: KeyPath<NavModel , Member>, _ mutation: () throws -> MutationResult ) rethrows -> MutationResult { // Crash occurs on the following line try _$observationRegistrar.withMutation(of: self, keyPath: keyPath, mutation) } @ObservationIgnored private var _section: SidebarSection? = .one To reproduce the crash, I tap a new item on the sidebar until the app crashes. It usually only takes 1-3 times selecting a new item before the crash occurs. Below is the code for an entire app to reproduce the crash. Has anyone else encountered this issue? Thank you! import SwiftUI @main struct NavigationBugApp: App { var body: some Scene { WindowGroup { ContentView() } } } @Observable class NavModel { var section: SidebarSection? = .one } enum SidebarSection: Hashable { case one case two } struct ContentView: View { @State private var model = NavModel() var body: some View { NavigationSplitView { List(selection: $model.section) { NavigationLink("One", value: SidebarSection.one) NavigationLink("Two", value: SidebarSection.two) } .listStyle(.sidebar) } detail: { Text("Hello World") } } } #Preview { ContentView() }
Replies
2
Boosts
0
Views
1.4k
Activity
Aug ’23
Party Planner Source Code? [wwdc2022-10052]
Is the complete source code for the Party Planner app available anywhere? The 'Code' tab in the Developer app only has snippets from the talk. (Sorry for having to post this in the wwdc20023 forum. The UI does not have any of the wwdc2022 tags in the picker anymore) Thanks.
Replies
1
Boosts
0
Views
650
Activity
Aug ’23
Using SettingsLink from MenuBarExtra does not activate the app
I have a Utility app that does not have a Dock icon and runs in the menu bar. On macOS Sonoma (14 DB 1) you cannot use anymore the workaround that we used on previous versions of the macOS, as you get a warning that you should use SettingsLink. NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil) But the issue is, that before I usually were calling as well NSApp.activate(ignoringOtherApps: true) to activate the app. As clicking on the MenuBar app icon does not do that. The SettingsLink only opens the Settings Scene, but does not actually activates the app. I could not find a workaround how to do so. As I cannot inject my code in SettingsLink call. Any ideas how I can activate my app when SettingsLink is called?
Replies
1
Boosts
2
Views
1.8k
Activity
Jul ’23
Why don't interactive buttons in iOS 17 widget call AppIntent perform() when the app running?
Inside a widget, there is a button, Button(intent: AnAppIntent()) { // Button's label. } // It seems this modifier does not add any value. .invalidatableContent() connected to an AppIntent. struct AnAppIntent: AppIntent { static var title: LocalizedStringResource = "An AppIntent" init() { // AppIntent required init. } func perform() async throws -> some IntentResult { // Never called when the app is running. return .result() } } The button calls AppIntent's perform() when tapped, and it consequently updates the widget UI (with or without the modifier .invalidatableContent()) only when the app is closed completely. If the app is alive in the background, perform() is not called, and the widget UI never updates. The user must explicitly dismiss the app to make the widget work as expected. The problem may be in the timeline used. struct SimpleEntry: TimelineEntry { let date: Date } struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) } func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) { completion(SimpleEntry(date: Date())) } func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { var entries: [SimpleEntry] = [] // Generate a timeline of five entries an hour apart, starting from the current date. let currentDate = Date() for hourOffset in 0 ..< 5 { let entryDate = Calendar.current.date(byAdding: .second, value: hourOffset, to: currentDate)! entries.append(SimpleEntry(date: entryDate)) } let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) } } However, if the problem were the timeline, the widget would not work with the app dismissed. Any idea on how to keep interactive widgets always working?
Replies
2
Boosts
1
Views
3.1k
Activity
Jun ’23
SwiftUI "Custom Gestures"
In Platforms State of the Union, there was a reference to "Custom Gestures" in SwiftUI, among new features. I didn't see anything about it in What's New with SwiftUI. Did I miss it? Anyone have more info?
Replies
0
Boosts
0
Views
869
Activity
Jun ’23
Customize DocumentGroup in SwiftUI with SwiftData
How do I customize my app's startup experience when using DocumentGroup in SwiftUI with SwiftData? I don't want my users to be greeted with a document browser on startup. Rather, I want to offer an experience like PhotoShop where the user is greeted by an "empty" version of my app's editor view. They can then use something like File->New or File->Open to get started.
Replies
1
Boosts
1
Views
1.2k
Activity
Jun ’23