Provide views, controls, and layout structures for declaring your app's user interface using SwiftUI.

SwiftUI Documentation

Posts under SwiftUI subtopic

Post

Replies

Boosts

Views

Activity

Content bleeding through `.fullScreenCover`
When building with the iOS 26 SDK (currently beta 4) and using the .fullScreenCover modifier in conjunction with a TabView, content from the background view bleeds through the .fullScreenCover making the UI fairly illegible. How to reproduce The gifs below show the bleed through in iOS 26 and the previous behavior of the same code in iOS 18. iOS 24 beta 4 iOS 18.5 Code The code below was used to demonstrate the issue seen in the gifs above. import SwiftUI struct FullScreenCoverBleed: View { @State private var isPresentingRegistration = false var body: some View { NavigationStack { TabView { Tab("Home", systemImage: "house") { Button("Create Account") { isPresentingRegistration = true } .buttonStyle(.borderedProminent) .fullScreenCover(isPresented: $isPresentingRegistration) { RegistrationWizard() } List { ForEach(1 ..< 11) { index in Text("Article \(index)") } } .listStyle(.plain) } Tab("Settings", systemImage: "gear") {} } } } } struct RegistrationWizard: View { var body: some View { // A page-style wizard TabView { // Page 1 VStack { Text("Page 1").font(.largeTitle) Text("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") Spacer() } // Page 2 Form { TextField("Username", text: .constant("")) // Fields for password, email, and so on ... } // Page 3 and so on... } .tabViewStyle(.page(indexDisplayMode: .automatic)) } } Where bleed-through occurs Starting View (before .fullScreenCover) Full Screen Cover VStack Full Screen Cover Form .sheet doesn't have this problem Interestingly, if you use a .sheet instead of a .fullScreenCover, everything works as expected. As shown below, there's no bleed-through when using a .sheet: Next steps? Is there a recommended way to prevent this bleed-through? Or is this perhaps a known bug in iOS 26 beta 4?
Topic: UI Frameworks SubTopic: SwiftUI
3
0
138
Jul ’25
Illegible navigation title when presenting Map view
When building with the iOS 26 SDK (currently beta 4), the navigation title is often illegible when rendering a Map view. For example, note how the title "Choose Location" is obscured by the map's text ("South America") in the screenshot below: This screenshot is the result of the following view code: import MapKit import SwiftUI struct Demo: View { var body: some View { NavigationStack { Map() .navigationTitle(Text("Choose Location")) .navigationBarTitleDisplayMode(.inline) } } } I tried using the scrollEdgeEffectStyle(_:for:) modifier to apply a scroll edge effect to the top of the screen, in hopes of making the title legible, but that doesn't seem to have any effect. Specifically, the following code seems to produce the exact same result shown in the screenshot above. import MapKit import SwiftUI struct Demo: View { var body: some View { NavigationStack { Map() .scrollEdgeEffectStyle(.hard, for: .top) // ⬅️ no apparent effect .navigationTitle(Text("Choose Location")) .navigationBarTitleDisplayMode(.inline) } } } Is there a recommended way to resolve this issue so that the navigation title is always readable?
4
3
176
Jul ’25
Swift UI の 日時表示の.timerでのコロン(:)のユニコードについて
I'm currently exploring ways to update a widget's display independently of the timeline mechanism. While researching, I came across this thread and started experimenting with the approach: https://developer.apple.com/forums/thread/720640 As part of the implementation, I'm attempting to render a 00:00-style time string using a single custom font glyph via .timer. However, I noticed that the colon character used in .timer doesn't appear to be the standard Unicode 0x003A (colon). It seems to be a different character entirely. Does anyone happen to know exactly which character this colon is? Any insights would be appreciated.
0
0
35
Jul ’25
iPadOS textFormatting menu does not appeared
I have this in my swift file: CommandGroup(replacing: .textFormatting) { Toggle("Bold Text", systemImage: "bold", isOn: boldBinding) .keyboardShortcut("B") Button("Align Left", systemImage: "text.alignleft") { alignmentBinding.wrappedValue = 1 } .keyboardShortcut("[") Button("Align Center", systemImage: "text.aligncenter") { alignmentBinding.wrappedValue = 0 } .keyboardShortcut("\\") Button("Align Right", systemImage: "text.alignright") { alignmentBinding.wrappedValue = 2 } .keyboardShortcut("]") } Nothing appeared in iPadOS menu (but does appeared on Mac). Change textFormatting to textEditing does work, but appeared in a very long menu
Topic: UI Frameworks SubTopic: SwiftUI
0
0
69
Jul ’25
iOS 26 Beta breaks scroll/gesture in SwiftUI chat (worked in iOS 18): Simultaneous gestures & ScrollViewReader issues
Hi all, After upgrading to the iOS 26 beta, the scrolling in my SwiftUI chat view is completely broken. The exact same code works perfectly on iOS 18. Context: I have a chat view using ScrollViewReader and a vertically-reversed ScrollView (with .rotationEffect(.degrees(180))). Each message row (MessageBubble) uses multiple simultaneousGesture handlers: Horizontal drag for swipe-to-reply (and other actions: pin, delete) Long press for showing popover/actions Vertical scroll for normal chat scrolling This was working great on iOS 18. In iOS 26 beta, the vertical scroll is either completely disabled, jittery, or hijacked by the message row’s drag gestures, even though .simultaneousGesture is used (see code below). Minimal Repro Sample MessageListView.swift swift Copy Edit ScrollViewReader { proxy in ScrollView(.vertical, showsIndicators: false) { LazyVStack(spacing: 0) { // ... grouped messages ForEach(...) { ... MessageBubble(...) // see below } Color.clear.frame(height: 8).id("BOTTOM_ANCHOR") } .padding(.horizontal, 4) .rotationEffect(.degrees(180)) } .rotationEffect(.degrees(180)) } MessageBubble.swift struct MessageBubble: View { // ... var body: some View { // horizontal swipe-to-reply gesture let dragGesture = DragGesture(minimumDistance: 10) // ... ZStack { // ... HStack { ... } // ... .simultaneousGesture( DragGesture(minimumDistance: 0) // for long press // ... ) .simultaneousGesture(dragGesture) // for horizontal swipe } // ... } }
5
7
245
Jul ’25
watchOS image alignment issue
Hello developers, Now I'm facing a issue with a image alingment on watchOS app. As you see below, I load a UIImage on a view of watchOS app using SwiftUI and would like to fill the watch screen fully with the image. (That's why I added '.ignoreSafeAre()' modifier) As expected, the image fills the screen but the image is aligned to the left only in case of a landscape image (width > height). I tried anything I imagine, but all failed. Can anybody give a hint or advice to solve this issue? Many thanks in advance! ZStack{ Image(uiImage: image) .resizable() .aspectRatio(contentMode: .fill) .ignoresSafeArea() .scaleEffect(zoom) .offset(...) .gesture(... }
0
0
60
Jul ’25
Using ConcentricRectangle as a ButtonBorderShape
With Xcode 26.0 Beta 4 the container concentric API is finally available, which is great! What I was wondering is how to use this API for button shapes. At the moment it seems that there is no ButtonBorderShape available that would behave like ConcentricRectangle. Is this intentional or is it expected that with upcoming beta versions we can also use the concentric style as button border shapes? Or is there maybe another way of getting the buttons shape to behave like a concentric shape? A use case I currently see is having the button as part of a container, using the .bordered button style and then aligning the corners of the button use the concentric style. Any information about this is highly appreciated. Thank you very much!
1
1
93
Jul ’25
UIViewControllerRepresentable breaks tab bar, ignores title and navigation items
In a UIKit-based project, I am attempting to integrate SwiftUI components. However, I encounter a persistent issue that hinders this integration. This problem arises when pushing a SwiftUI view using UIHostingController and subsequently attempting to push a UIKit view controller using UIViewControllerRepresentable. Not only are the navigation items and title from the view controller disregarded, but more concerningly, my tab bar item title is set to nil. This renders it impossible for me to utilize SwiftUI within my application when I wish to present older UIKit view controllers from there. This feedback has all the details and a sample project. FB18956999
1
1
127
Jul ’25
Pushing a UIHostingController has delayed toolbar items and title transitions
For over five years, this persistent issue has affected all platforms, and despite submitting numerous feedback reports, my concerns have remained unaddressed. When utilizing a UIHostingController within a UINavigationController, the toolbar items and title defined in the SwiftUI view manifest with a substantial delay. This delay is particularly noticeable with the introduction of Liquid Glass, resulting in a jarring transition. Although I had nearly lost hope, the issue was resolved in iOS 26 beta 3 when the push occurs from within a UISplitViewController. However, the problem persists outside of this context. Ultimately, this issue hinders my ability to develop high-quality applications and restricts my use of SwiftUI within my UIKit project for similar purposes. I sincerely hope that this issue can be resolved, enabling me to fully rely on SwiftUI in my project. Please prioritize this matter and make the necessary changes that were already made in UISplitViewController. This feedback has all the details and a sample project. FB14000542 Before the push: During the push: A second after the push finishes:
0
1
121
Jul ’25
The new navigationLinkIndicatorVisibility modifier crashes on < iOS 26
This new modifier is supposedly backported to iOS 17, but on attempting to use it on the latest iOS 18.5, this happens: Symbol not found: _$s7SwiftUI17EnvironmentValuesV33_navigationIndicatorVisibilityABIAA0G0OvpMV This happens with any usage of the modifier. An availability check won't save you either. The cruelest part of this is that I only need the modifier on iOS 26, lmao. Am I just missing something?
Topic: UI Frameworks SubTopic: SwiftUI
8
0
186
Jul ’25
TabView + NavigationStack + ScrollView navigationTitle bug
Hello there! I've been struggline with this thing for a two days now, and seems like it's a bug in SwiftUI. Navigation title is jumping on top of the ScrollView's content when switching tabs in TabView. Steps to reproduce: Scroll one tab to the bottom so that the large title is hidden and the floating toolbar appears. Go to another tab in the tab bar. Go back to the initial tab (it is still scrolled), and press the current tab button again to scroll to the top. The navigation title will glitch and be on top of the content. The animation fixes if you scroll again manually. Video: https://share.cleanshot.com/PFCSKMlH Code (simplified): import SwiftData import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { TabsContentView() } } } // ... struct TabsContentView: View { enum Tab { case library, profile } @State private var selectedTab: Tab = .library var body: some View { TabView(selection: $selectedTab) { NavigationStack { YourLibraryList() .navigationTitle("Your Library") } .tabItem { Label("Library", systemImage: "tray.fill") } .tag(Tab.library) NavigationStack { VStack { Spacer() Text("Profile") .font(.largeTitle) .foregroundColor(Color.theme.text) Text("Manage your account and preferences here") .font(.body) .foregroundColor(Color.theme.mutedForeground) .multilineTextAlignment(.center) .padding(.horizontal) Spacer() } .navigationTitle("Explore") } .tabItem { Label("Profile", systemImage: "person.fill") } .tag(Tab.profile) } .toolbarBackground(.ultraThinMaterial, for: .tabBar) .toolbarBackground(.visible, for: .tabBar) } } // ... struct YourLibraryList: View { var body: some View { ScrollView { VStack(spacing: 12) { ForEach(1 ... 20, id: \.self) { number in RoundedRectangle(cornerRadius: 12) .fill(Color.blue.opacity(0.1)) .stroke(Color.blue, lineWidth: 1) .frame(height: 60) .overlay( Text("\(number)") .font(.title2) .fontWeight(.semibold) .foregroundColor(.blue) ) } } .padding(.horizontal) } } }
2
0
202
Jul ’25
Unable to Drag 3D Model(Entity) in visionOS when UITextView Is in the Background
I'm running into an issue in Xcode when working on a visionOS app. Whenever I try to drag a 3D model entity in my scene, the drag gesture doesn't work if there's a UITextView (or SwiftUI TextEditor) in background of the 3D entity. It seems like the UITextView is intercepting the gesture or preventing the drag interaction from reaching the 3D content. Interestingly, when the 3D entity is placed infront of the ScrollView, the drag works as expected. Has anyone else experienced this behavior? Is this a known limitation or a bug in the current tooling? Any workarounds or fixes would be appreciated. Thanks!
0
0
133
Jul ’25
High CPU Usage in SwiftUI UIHostingController on iOS 26 Beta
Experiencing 100% CPU usage in SwiftUI app using UIHostingController, only on iOS 26 beta and Xcode beta. Issue involves excessive view updates in AttributeGraph propagation. Stack trace (main thread): thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame #0: 0x00000001c38b9aa4 AttributeGraph`AG::Graph::propagate_dirty(AG::AttributeID) + 416 frame #1: 0x00000001d9a743ec SwiftUICore`SwiftUI.ObservationGraphMutation.apply() -> () + 656 frame #2: 0x00000001d97c0d4c SwiftUICore`function signature specialization <Arg[2] = [Closure Propagated : closure #1 () -> () in SwiftUI.(AsyncTransaction in _F9F204BD2F8DB167A76F17F3FB1B3335).apply() -> (), Argument Types : [SwiftUI.AsyncTransaction]> of generic specialization <()> of closure #1 () throws -> τ_0_0 in SwiftUI.withTransaction<τ_0_0>(SwiftUI.Transaction, () throws -> τ_0_0) throws -> τ_0_0 + 336 frame #3: 0x00000001d9a6ac80 SwiftUICore`merged function signature specialization <Arg[3] = Owned To Guaranteed> of function signature specialization <Arg[1] = [Closure Propagated : implicit closure #2 () -> () in implicit closure #1 @Sendable (SwiftUI.(AsyncTransaction in _F9F204BD2F8DB167A76F17F3FB1B3335)) -> () -> () in SwiftUI.GraphHost.flushTransactions() -> (), Argument Types : [SwiftUI.AsyncTransaction]> of SwiftUI.GraphHost.runTransaction(_: Swift.Optional<SwiftUI.Transaction>, do: () -> (), id: Swift.Optional<Swift.UInt32>) -> () + 196 frame #4: 0x00000001d9a52ab0 SwiftUICore`SwiftUI.GraphHost.flushTransactions() -> () + 176 frame #5: 0x00000001d8461aac SwiftUI`closure #1 (SwiftUI.GraphHost) -> () in SwiftUI._UIHostingView._renderForTest(interval: Swift.Double) -> () + 20 frame #6: 0x00000001d9bf3b38 SwiftUICore`partial apply forwarder for closure #1 (SwiftUI.ViewGraph) -> τ_1_0 in SwiftUI.ViewGraphRootValueUpdater.updateGraph<τ_0_0>(body: (SwiftUI.GraphHost) -> τ_1_0) -> τ_1_0 + 20 frame #7: 0x00000001d9e16dc4 SwiftUICore`SwiftUI.ViewGraphRootValueUpdater._updateViewGraph<τ_0_0>(body: (SwiftUI.ViewGraph) -> τ_1_0) -> Swift.Optional<τ_1_0> + 200 frame #8: 0x00000001d9e1546c SwiftUICore`SwiftUI.ViewGraphRootValueUpdater.updateGraph<τ_0_0>(body: (SwiftUI.GraphHost) -> τ_1_0) -> τ_1_0 + 136 frame #9: 0x00000001d8461a7c SwiftUI`closure #1 () -> () in closure #1 () -> () in closure #1 () -> () in SwiftUI._UIHostingView.beginTransaction() -> () + 144 frame #10: 0x00000001d846aed0 SwiftUI`partial apply forwarder for closure #1 () -> () in closure #1 () -> () in closure #1 () -> () in SwiftUI._UIHostingView.beginTransaction() -> () + 20 frame #11: 0x00000001d984f814 SwiftUICore`closure #1 () throws -> τ_0_0 in static SwiftUI.Update.ensure<τ_0_0>(() throws -> τ_0_0) throws -> τ_0_0 + 48 frame #12: 0x00000001d984e114 SwiftUICore`static SwiftUI.Update.ensure<τ_0_0>(() throws -> τ_0_0) throws -> τ_0_0 + 96 frame #13: 0x00000001d846aeac SwiftUI`partial apply forwarder for closure #1 () -> () in closure #1 () -> () in SwiftUI._UIHostingView.beginTransaction() -> () + 64 frame #14: 0x00000001851eab1c UIKitCore`___lldb_unnamed_symbol311742 + 20 * frame #15: 0x00000001852b56a8 UIKitCore`___lldb_unnamed_symbol315200 + 44 frame #16: 0x0000000185175120 UIKitCore`___lldb_unnamed_symbol308851 + 20 frame #17: 0x00000001d984e920 SwiftUICore`static SwiftUI.Update.dispatchImmediately<τ_0_0>(reason: Swift.Optional<SwiftUI.CustomEventTrace.ActionEventType.Reason>, _: () -> τ_0_0) -> τ_0_0 + 300 frame #18: 0x00000001d95a7428 SwiftUICore`static SwiftUI.ViewGraphHostUpdate.dispatchImmediately<τ_0_0>(() -> τ_0_0) -> τ_0_0 + 40 frame #19: 0x00000001852b59dc UIKitCore`___lldb_unnamed_symbol315204 + 192 frame #20: 0x00000001852b54a4 UIKitCore`___lldb_unnamed_symbol315199 + 64 frame #21: 0x0000000185745dd4 UIKitCore`_UIUpdateSequenceRunNext + 120 frame #22: 0x0000000186144fac UIKitCore`schedulerStepScheduledMainSectionContinue + 56 frame #23: 0x00000002505ad150 UpdateCycle`UC::DriverCore::continueProcessing() + 36 frame #24: 0x0000000180445b20 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 frame #25: 0x0000000180445a68 CoreFoundation`__CFRunLoopDoSource0 + 168 frame #26: 0x00000001804451f4 CoreFoundation`__CFRunLoopDoSources0 + 220 frame #27: 0x00000001804443a8 CoreFoundation`__CFRunLoopRun + 756 frame #28: 0x000000018043f458 CoreFoundation`_CFRunLoopRunSpecificWithOptions + 496 frame #29: 0x00000001928d19bc GraphicsServices`GSEventRunModal + 116 frame #30: 0x0000000186224480 UIKitCore`-[UIApplication _run] + 772 frame #31: 0x0000000186228650 UIKitCore`UIApplicationMain + 124 frame #32: 0x000000010bb1b504 MyApp.debug.dylib`main at main.swift:13:1 frame #33: 0x00000001043813d0 dyld_sim`start_sim + 20 frame #34: 0x000000010468ab98 dyld`start + 6076 Used let _ = Self.printChanges() in my SwiftUI View and got infinite changes of \_UICornerProvider.<computed 0x000000018527ffd8 (Optional<UICoordinateSpace>)> changed. Reproduces only on beta; works on stable iOS. Likely beta-specific bug in SwiftUI rendering.
7
1
317
Jul ’25
Recommended / Canonical way to host remote (separate process) SwiftUI views.
I am building a tool that enables the user to write, auto-compile and interact with SwiftUI code (think something like a mini Xcode Canvas). Which so far works really well. The app is not sandboxed since it uses tools like swiftc and sourcekit-lsp. The obvious problem here is that since the 'Preview' part of the app is driven by arbitrary code a crash/hang there would lead to a termination of the whole app. I understand that there are some private apis like NSRemoteView or CALayerHost but I would like to avoid them if I can. From what I see reading other similar solutions IOSurface sharing + event forwarding might be the best solution. So my question is: Is there a proper or recommended way to achieve this? Meaning having a fully interactive SwiftUI view presented in my host app but running on a separate process? Any pointers to the right direction or examples or whatever could help me with this would be greatly appreciated.
4
0
166
Jul ’25
Broken Constraints on macOS 26 SwiftUI App
I have a SwiftUI-lifecycle Mac app that uses a standard NavigationSplitView. When it runs on macOS 26 Beta 3, I see invalid constraint messages in the debugger at launch and when I navigate around the app's UI: Since this app is 100% SwiftUI, I'm not adding my own constraints. The invalid constraint is always the same. This has happened on every beta of macOS 26 and DOES NOT happen on macOS 14 or 15. I've filed feedback reports with no answer. Has anyone else encountered this with the betas?
Topic: UI Frameworks SubTopic: SwiftUI
1
0
98
Jul ’25
iOS 26 beta: Section headers no longer show translucent background when pinned with .listStyle(.plain)
Hi everyone, I've noticed a significant change in the visual behavior of List section headers between iOS 18 and iOS 26 beta that I'd like to clarify. Current Behavior: iOS 18 and earlier: Section headers with .listStyle(.plain) display with a translucent material background (regular material with blur effect) when pinned to the top during scrolling iOS 26 beta: Section headers with .listStyle(.plain) appear with a transparent/clear background even when pinned to the top Sample Code: struct ContentView: View { var body: some View { NavigationStack { List(1 ..< 5) { headerIndex in Section { ForEach(1...5, id: \.self) { rowIndex in HStack { Text("Row \(rowIndex)") .frame(height: 40) .padding(.horizontal) .background(Color.blue) Spacer() Image(systemName: "chevron.right") .foregroundStyle(.secondary) .font(.title3) } } } header: { Text("Header \(headerIndex)") .frame(height: 44) } .listRowSeparator(.hidden) } .listStyle(.plain) .clipped() } } } Questions: Is this change in header background behavior for .plain list style intentional in iOS 26? If so, what's the recommended way to maintain the previous material background appearance when headers are pinned? Should this be filed as feedback if it's unintended behavior? Testing Environment: Xcode 26.0 beta 3 (17A5276g) iOS 26 beta (23A5287g) vs iOS 18.5 Tested on simulator The translucent header background when pinned was quite useful for maintaining readability over scrolling content, so I'm hoping to understand if this is the new expected behavior or if there's a way to preserve the previous appearance. Any insights would be greatly appreciated! iOS 18.5 iOS 26 Beta
2
1
158
Jul ’25
List selection does not update model on MacOS. But same code works fine on iOS.
I have this code example that works perfectly on iOS. But on MacOS, the changes made in view presented by Navigation Stack gets reverted after I click on Back button. import SwiftUI import Observation enum Route: Hashable { case selection } let allSelectables: [String] = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"] @Observable class Model { var items: Set<String> = [] // Use Set for unique selections } struct ContentView: View { @State var model = Model() var body: some View { NavigationStack { VStack { Text("Selected: \(model.items.joined(separator: ", "))") List { NavigationLink(value: Route.selection) { Text("Go to Selection (\(model.items.count))") } } .navigationDestination(for: Route.self) { route in switch route { case .selection: List(allSelectables, id: \.self, selection: $model.items) { item in Text(item) } #if os(iOS) .environment(\.editMode, .constant(.active)) // Enable multiple selection #endif .navigationTitle("Selected: \(model.items.joined(separator: ", "))") } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI
1
0
96
Jul ’25
Multi-Selection List : changing Binding Array to Binding Set and back again
I am trying to create a menu picker for two or three text items. Small miracles, but I have it basically working. Problem is it uses a set, and I want to pass arrays. I need to modify PickerView so the Bound Parameter is an [String] instead of Set. Have been fighting this for a while now... Hoping for insights. struct PickerView: View { @Binding var colorChoices: Set<String> let defaults = UserDefaults.standard var body: some View { let possibleColors = defaults.object(forKey: "ColorChoices") as? [String] ?? [String]() Menu { ForEach(possibleColors, id: \.self) { item in Button(action: { if colorChoices.contains(item) { colorChoices.remove(item) } else { colorChoices.insert(item) } }) { HStack { Text(item) Spacer() if colorChoices.contains(item) { Image(systemName: "checkmark") } } } } } label: { Label("Select Items", systemImage: "ellipsis.circle") } Text("Selected Colors: \(colorChoices, format: .list(type: .and))") } } #Preview("empty") { @Previewable @State var colorChoices: Set<String> = [] PickerView(colorChoices: $colorChoices) } #Preview("Prefilled") { @Previewable @State var colorChoices: Set<String> = ["Red","Blue"] PickerView(colorChoices: $colorChoices) } My Content View is suppose to set default values the first time it runs, if no values already exist... import SwiftUI struct ContentView: View { @State private var viewDidLoad: Bool = false var body: some View { HomeView() .onAppear { // The following code should execute once the first time contentview loads. If a user navigates back to it, it should not execute a second time. if viewDidLoad == false { viewDidLoad = true // load user defaults let defaults = UserDefaults.standard // set the default list of school colors, unless the user has already updated it prior let defaultColorChoices: [String] = ["Black","Gold","Blue","Red","Green","White"] let colorChoices = defaults.object(forKey: "ColorChoices") as? [String] ?? defaultColorChoices defaults.set(colorChoices, forKey: "ColorChoices") } } } } #Preview { ContentView() } PickLoader allows you to dynamically add or delete choices from the list... import SwiftUI struct PickLoader: View { @State private var newColor: String = "" var body: some View { Form { Section("Active Color Choices") { // we should have set a default color list in contentview, so empty string should not be possible. let defaults = UserDefaults.standard let colorChoices = defaults.object(forKey: "ColorChoices") as? [String] ?? [String]() List { ForEach(colorChoices, id: \.self) { color in Text(color) } .onDelete(perform: delete) HStack { TextField("Add a color", text: $newColor) Button("Add"){ defaults.set(colorChoices + [newColor], forKey: "ColorChoices") newColor = "" } } } } } .navigationTitle("Load Picker") Button("Reset Default Choices") { let defaults = UserDefaults.standard //UserDefaults.standard.removeObject(forKey: "ColorChoices") let colorChoices: [String] = ["Black","Gold","Blue","Red","Green","White"] defaults.set(colorChoices, forKey: "ColorChoices") } Button("Clear all choices") { let defaults = UserDefaults.standard defaults.removeObject(forKey: "ColorChoices") } } } func delete(at offsets: IndexSet) { let defaults = UserDefaults.standard var colorChoices = defaults.object(forKey: "ColorChoices") as? [String] ?? [String]() colorChoices.remove(atOffsets: offsets) defaults.set(colorChoices, forKey: "ColorChoices") } #Preview { PickLoader() } And finally HomeView is where I am testing from - to see if binding works properly... import SwiftUI struct HomeView: View { //@State private var selection: Set<String> = [] //@State private var selection: Set<String> = ["Blue"] @State private var selection: Set<String> = ["Blue", "Red"] var body: some View { NavigationStack { List { Section("Edit Picker") { NavigationLink("Load Picker") { PickLoader() } } Section("Test Picker") { PickerView(colorChoices: $selection) } Section("Current Results") { Text("Current Selection: \(selection, format: .list(type: .and))") } } .navigationBarTitle("Hello, World!") } } } #Preview { HomeView() } If anyone uses this code, there are still issues - buttons on Loader don't update the list on the screen for one, and also dealing with deleting choices that are in use - how does picker deal with them? Probably simply add to the list automatically and move on. If anyone has insights on any of this also, great! but first I just need to understand how to accept an array instead of a set in pickerView. I have tried using a computed value with a get and set, but I can't seem to get it right. Thanks for any assistance! Cheers!
2
0
159
Jul ’25
"The compiler is unable to type-check this expression..."
"/Users/rich/Work/IdeaBlitz/IdeaBlitz/IdeaListView.swift:30:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions" Is it just me? I get this on syntax errors, missing commas, missing quotes, and for no particular reason at all that I can see. I don't think I've been able to write a single, simple, SwiftUI view without seeing this multiple times. "Breaking it up" just makes it harder to read. Simple, inline, 2-page views become 8-page, totally unreadable, monstrosities. Am I doing something wrong? Or is this just the state of SwiftUI today? Or is there some way to tell the compiler to take more time on this expression? I mean, if these can be broken up automatically, then why doesn't the compiler to that already?
2
0
167
Jul ’25
Logo flying from the corner
Whenever I load a resized image into a 70 by 70 frame, when I run the loading screen on the simulator, it looks like the image is flying from the top left corner of the screen on load, however, when I load it in the previews, it starts where its supposed to be in the center. Both are scaled properly, however, the first ones position is acting like I put a transition on it when I did not import SwiftUI struct LoadingView: View { @Environment(\.colorScheme) private var colorScheme var text: String? = nil @State private var isSpinning = false var body: some View { VStack{ Image("Jeromes_Logo") .resizable() .frame(width: 70, height: 70) .rotationEffect(.degrees(isSpinning ? 360 : 0)) .animation( .bouncy(duration: 0.4, extraBounce: 0.2) .repeatForever(autoreverses: false), value: isSpinning ) .onAppear { isSpinning = true } if let text = text { Text(text) } } .frame(maxWidth: .infinity, maxHeight: .infinity) } } #Preview { LoadingView(text: "loading") }
2
0
446
Jul ’25