Skip to main content
1 vote
0 answers
63 views

How to open and display different files in WindowGroup windows (tabs) using fileImporter from CommandGroup on the WindowGroup?

In code below the @State var modelData initializes with empty structures, and in that case the ContentView shows nothing. (This is fine.) The modelData can also initialize from a file obtained from ...
TT--'s user avatar
  • 3,288
0 votes
2 answers
226 views

LazyGrid with onTap gesture on items does not work as intended with sheet presentation

I am trying to understand @State. Ignoring the view model in the picture, I am trying to present a view modally with sheet modifier on tapping any item on my lazygrid. For some reason an empty view is ...
mshrestha's user avatar
  • 706
0 votes
1 answer
28 views

Why does the state change back to original state?

I'm new to SwiftUI and I couldn't understand why the selectedUser is set to nil on the fullScreenCover block. Note that User is a class from a third party library and doesn't conform to ...
osrl's user avatar
  • 7,848
1 vote
1 answer
222 views

Navigation state restoration with NavigationStack breaks binding

I'm developing an iOS app that lists items in a List inside a NavigationStack. When the user clicks on a item it shows its details, and if he clicks then on the Edit button, he can edit its values (on ...
Enric's user avatar
  • 350
0 votes
1 answer
628 views

Publishing a Var from Another @ObservableObject During Init()

How does one publish a property from another ObservableObject which is created during initialization? I want to ensure a specific property is captured as a @Published/@Binding/@State variable (so it's ...
TheNeil's user avatar
  • 3,802
6 votes
3 answers
2k views

How to pass the result of @Query as Binding to a view

I want to pass some queried data from SwiftData in other views that receive a Binding array. Like the example below: struct View1: View { @Query var data: [MyModel] var body: some View { ...
Tony Cheng's user avatar
1 vote
1 answer
588 views

Executing Code Based on Elapsed Time in SwiftUI's TimelineView

Lets say you have a SwiftUI app where you are implementing navigation like this: import SwiftUI enum ScreenToShow { case main, child } @Observable class NavigationController { var screen: ...
Nerdy Bunz's user avatar
  • 7,723
3 votes
1 answer
2k views

SwiftUI view is not updating when embedded into UIHostingController

I have the following simple SwiftUI view: struct ContentView: View { var body: some View { Text(self.label) } @State var label = "Initial text." } This view is embedded ...
goofy4224's user avatar
  • 330
0 votes
1 answer
184 views

SwiftUI - immutable @State variable when change it "from outside" via UIHostController

Situation During migration of some UIKit view classes to SwiftUI, I have faced next case: I have a simple view class, responsible for data fetching and displaying. Its structure is pretty simple and ...
Viktor's user avatar
  • 1,177
6 votes
3 answers
984 views

SwiftUI: Bound @State Variable Not Updated When Showing Sheet

I am experiencing an issue with SwiftUI where a bound @State variable (displayString) does not seem to get updated in time when a sheet is presented. The code provided consists of a parent view (...
Nerdy Bunz's user avatar
  • 7,723
-1 votes
1 answer
53 views

Weird @Binding behavior, doesn't update the value until I set it into different one

So I have this simple test code to test how I can communicate between two views using @Binding. It's supposed to be simple in which there's a list of buttons that when it's pressed it'll open a simple ...
foolinaroundz's user avatar
0 votes
0 answers
851 views

SwiftUI Button animation

I use ButtonStyle, for button style. But when I updated button from enable to disable, and change thread, the button change without animation. //I have ButtonStyle: struct WizardButtonStyle: ...
Medoed's user avatar
  • 1
0 votes
1 answer
356 views

NavigationView doesn't update when @State changes (NavigationStack works well)

I encountered this situation when trying to replace my NavigationStack (iOS 16+) by a NavigationView (for backward compatibility reasons). What I hoped for would be that NavigationStack and ...
IMAGE-ET's user avatar
3 votes
4 answers
4k views

SwiftUI State in Preview with PreviewProvider is not working

I've a simple button that work on simulator as expected, the shape changes with click; struct ButtonTest: View { @State var isLiked = true var body: some View { VStack { ...
kelalaka's user avatar
  • 5,706
0 votes
3 answers
1k views

setTitleColor not working for custom UIButton in .disabled state

I have a form to collect basic user info. There is a "Continue" button on the form that has different appearances based on whether it is in the .enabled or .disabled state. The .enabled ...
Farquad's user avatar

15 30 50 per page