Category "swiftui"

How to navigate between NavigationLink while leave a part of main window stay the same in SwiftUI

I would like to navigate between different NavigationLinks in NavigationView while some part of the main window stay the same. For example, I want to make a mus

How to navigate between NavigationLink while leave a part of main window stay the same in SwiftUI

I would like to navigate between different NavigationLinks in NavigationView while some part of the main window stay the same. For example, I want to make a mus

How do you get a bound variable to clear?

If $score is bound to score, how come the textfield won't clear? How do I make it clear? Also, how would I get "Enter Score" to show rather than "0"? Thanks. im

How to use array of ForEach in SwiftUI

I would like to create an array with a ForEach loop. Something like this : let a = [ ForEach(b) { c in "create the element in the array" } ] H

Extension function is inaccessible due to 'internal' protection level

So I have this lovely extension that would allow me to write conditional view modifiers to my views, made by Antoine van der Lee https://www.avanderlee.com/swif

SwiftUI - Snapshot a variable as a value instead of a pointer so it is not updated during DragGesture .onchanged lifecycle

I am trying to move a CGPoint (greenPoint) by moving another one (bluePoint). The distance and angle must remained the same. In order to capture that, I store t

SwiftUI NavigationView detail view binding to sheet modal not working

I have a List where the navigationLink destination is a view with a binding property for a user struct. works fine, if in the detail view I create another navig

SwiftUI text field orphan on macOS

I have a text field like this Text("Hello, one two three four five six seven eight!") .frame(width:270) .border(.blue) When it

SwiftUI List Selection: Have to Tap Twice to Deselect Item Initially

Why do you have to tap twice to deselect "Item 1"? Am I doing something wrong? If not, is there a workaround? It happens both in the simulator and on my iPhone.

Text not updating when variable updates in SwiftUI (Swift 5, Xcode 13)

I have this variable, timeRemaining and when a button is pressed it should subtract one from timeRemaining. I want the Text to update whenever the user clicks t

Fetching data in Preview: "A fetch request must have an entity UncaughtExceptionError"

I have a ListView file which can build the preview code fine without the Core Data piece in it. However, when I build that ListView in the ContentView, I got a

SwiftUI - How to center a component in a horizontal ScrollView when tapped?

I have a horizontal ScrollView, and within it an HStack. It contains multiple Subviews, rendered by a ForEach. I want to make it so that when these Subviews are

SwiftUI toolbar text size changes on appear

Related to this I am trying to make an app based on Notes app. I set my iPhone text size to the smallest, and when the view changes, the texts on new view's to

Changing the toolbar item placement on iPad

Let's take the Shortcuts app for example. On the iOS App: On the iPadOS App: As you can see, the toolbar items were on .navigationBarTrailing on iPhone, but i

SwiftUI, AppStorage and using Picker in TabViews

I am trying to save a small amount of data with picker using AppStorage across multiple views. However the issue I'm running into is that when I select one valu

SwiftUI : How I can delete the UIimage in the View saved as Codable?

I tried to save the image in my memo with as UIImage as Codable protocol. My code can be a little bit longer, but please refer to it. 1. first one is the NewMem

View is not updated when the data is changed with ForEach

I want to change rate parameter and display in ForEach. // ViewModel.swift @MainActor final class ViewModel: ObservableObject { let serviceContainer: Servi

Why does SwiftUI View background extend into safe area?

Here's a view that navigates to a 2nd view: struct ContentView: View { var body: some View { NavigationView { NavigationLink {

My view doesn't update after modifying an object of a list inside an ObservableObject

I am new to SwiftUI. Imagine I am building an app for a shop. I have a view that is a list of the details of a product, and two buttons: Pin (add to favorites)

How to save a UUID in SwiftUI using @AppStorage

When using @AppStorage("navigationWaypointID") var navigationWaypointID: UUID? I get a No exact matches in call to initializer. I can work around by using a St