Questions tagged [swiftui-environment]
141 questions
36
votes
2 answers
Where to configure Firebase in my iOS app in the new SwiftUI App life cycle without AppDelegate and SceneDelegate?
I have an app already that I was able to build completely with SwiftUI.
I was using Firebase for authentication and notifications using Cloud Functions.
Now with the new SwiftUI App->Scene->View construct, I am unable to add the setup to my app.
For…

thenakulchawla
- 5,024
- 7
- 30
- 42
12
votes
2 answers
Set Image and Title in Navigation Bar in SwiftUI
Would really appreciate it if anyone knows how to implement it or ideas on how to do it.

pushpank
- 262
- 3
- 9
7
votes
1 answer
SwiftUI recompiles pods and everything every time
I am playing around with SwiftUI and looks pretty interesting however I am facing very annoying performance issues.
When I create a new SwiftUI file or make a large change in a SwiftUI view, XCode would start recompiling everything. It would…

mrtksn
- 412
- 3
- 18
7
votes
2 answers
SwiftUI passing data between multiple classes
After scouring Apple's SwiftUI docs, the web and stackoverflow, I can't seem to figure out how to use multiple classes and passing EnviromentObject data between them. All the articles on SwiftUI's EnvironmentObject, ObservableObjects, Bindings show…

Ryan
- 10,798
- 11
- 46
- 60
5
votes
1 answer
Create different stroke styles on same Path - SwiftUI (Based on value between 0-1 like gradient)
In SwiftUI Shapes we can make different color strokes by using gradients.
Eg -
@ViewBuilder
func lineWithSecondColorStyleFromPositionN() -> some View {
let n = 0.5
GeometryReader { gr in
Path { path in
path.move(to:…

Kunal Verma
- 562
- 4
- 15
5
votes
1 answer
SwiftUI Timer.publish causing whole screen to refresh
GIF of Entire Screen Refreshing
I am currently learning combine and MVVM. My problem is when I try to use a timer.publish, eventually I'm going to create a stop button, it causes the entire screen to refresh instead of the Text I have .onReceive. …

Zeimin
- 53
- 4
5
votes
2 answers
Editor only view in XCode
I am using swiftUI to write a new app. Every-time I open a new file the Canvas opens up.
I want the default view to be "Only Editor" and I can open the canvas whenever I want to manually.
Is there a way to change the default?

thenakulchawla
- 5,024
- 7
- 30
- 42
5
votes
2 answers
Displaying a published integer in SwiftUI Text
I am fairly new to SwiftUI and ran into the following problem:
I have a model that contains some integer values like so:
class Game: ObservableObject {
@Published var ownScore:Int = 0
@Published var opponentScore:Int = 0
... some…

Tobilence
- 115
- 1
- 6
5
votes
1 answer
SwiftUI: Sort list based on an @Published variable
I'm building a UI with SwiftUI, and I have an array that I use to build a List element. Now I want to sort that list based on a @Published variable coming from an @EnvironmentObject.
Approach 1
I tried getting the array already sorted, passing in…

BlackWolf
- 5,239
- 5
- 33
- 60
4
votes
0 answers
Programmatically show the pull to refresh activity indicator of a refreshable List
I wonder if there's a simple way to make visible the activity indicator used by the refresh control of a SwiftUI List? This would provide a consistent appearance of a refreshing UI, regardless of how the refresh was initiated.
After enabling pull to…

Andreas
- 2,665
- 2
- 29
- 38
4
votes
2 answers
How to assign default modifiers to a SwiftUI view?
I'm trying to make reusable custom views that themselves can be customized later. Ideally I'd be able to define default modifiers like Color, Font, etc that the Views would have without any customization, but allow these to be easily overwritten by…

Caleb Bolton
- 41
- 3
4
votes
1 answer
Initialize app with an Async function | SwiftUI
I need my app to configure the backend at start, here's the function to do so:
// Initializes Amplify
final func configureAmplify() async {
do {
// Amplify.Logging.logLevel = .info
let dataStore =…

Arturo
- 3,254
- 2
- 22
- 61
4
votes
1 answer
Build Error Previewing First SwiftUI View
I'm incorporating SwiftUI into my project for the very first time!
Unfortunately I can't preview my first SwiftUI file I add to the project. The build only fails on the preview. And the failure is in my tests.
Steps to build error:
Click the…

TheJeff
- 3,665
- 34
- 52
3
votes
1 answer
How to Keep state of my View Model persistent across a user session in SwiftUI (MVVM)?
I am trying to implement an IOS App following the MVVM architecture. Everything works well when I don't need my state to be persistent as I move through views and navigate back.
However, when a user navigates two or three steps back to View, I want…

Khalil Hajji
- 51
- 3
3
votes
1 answer
How to dismiss sheet from within NavigationLink
In the following example, I have a view that shows a sheet of ViewOne. ViewOne has a NavigationLink to ViewTwo.
How can I dismiss the sheet from ViewTwo?
Using presentationMode.wrappedValue.dismiss() navigates back to ViewOne.
struct ContentView:…

Isaak
- 1,107
- 2
- 11
- 29