Questions tagged [swiftui-environment]

141 questions
0
votes
0 answers

Problem login screen with swiftUi navigate to ViewController

I created a login screen using SwiftUI. When I press a login button (after the validation of email and password), it navigates to a ViewController. Login state is stored in a userDefault Boolean for use later when the app is launched again. In…
0
votes
2 answers

How to pass array of string from to view model to play song in swiftUI

I've created a model and added nested struct. created an array based on one of the struct details and I want to retrieve the details from Model to view model to play the music. I want to retrieve this "aURL" strings and insert it inside the play…
0
votes
2 answers

Swiftui , Buttons grid view

I have checked several questions here about the grid view but my question is a bit different , i want to create a grid view for buttons so each button when pressed navigate to different view, So it has look like this image: This is the grid buttons…
0
votes
1 answer

Modifying an environment object, clear data from another one on SwiftUI

I am having a view with two environment objects. I am displaying data from one of them, and modify data on the other one. When I change the data on the first object, another instance will be created of the second object and its data is cleared. I…
Noura
  • 722
  • 10
  • 24
0
votes
1 answer

Method with No observable object

I have a class method that apparently doesn't see the @EnvironmentObject var categories: Categories object at the top of the class. I know that this works since I use it in several other files. It also means that my coding in SceneDelegate is…
Galen Smith
  • 299
  • 2
  • 14
0
votes
1 answer

SwiftUI DocumentGroup and switching to background

I have made an app based on the new SwiftUI multi platform target for a "Document based app". However, I face weird issues. As long as an app is in the foreground, it works just fine. If it is moved to the background by task switching, and then…
Jan
  • 1,582
  • 1
  • 13
  • 19
0
votes
1 answer

Accessing @Environment(\.presentationMode) stopping PDFView from appearing

Problem: Accessing @Environment(.presentationMode) stops my PDFView from being shown. Working Code: Displays a pdf document via PDFViewer within MainView import SwiftUI struct MainView: View { @State var pdfDocument: PDFDocument =…
swift--help
  • 637
  • 5
  • 15
0
votes
0 answers

Is there a better way to pass around state in SwiftUI other than EnvironmentObjects?

I'm fairly new to SwiftUI. I'm creating a survey view. In it, I load data from a Plist to show a list of multiple choice questions. I've created the following: SurveyView (holds the whole survey) SurveyQuestionView (holds a single multiple choice…
Matthew Knippen
  • 1,048
  • 9
  • 22
0
votes
1 answer

Unable to access @EnvironmentObject from a child view constructed with a function

I'm trying to pass an EnvironmentObject to child views but am having no luck with the following code. struct ContentView: View { enum MyViews: Int, CaseIterable { case introView case viewOne case viewTwo var activeView: AnyView…
Ribena
  • 1,086
  • 1
  • 11
  • 20
0
votes
0 answers

SwiftUI best practices: should View have a constant to singletons and should they be passed in the Environment?

In Xcode 12 template for a SwiftUI project using Core Data, Apple provides the following code: import SwiftUI @main struct CoreDataApp: App { let persistenceController = PersistenceController.shared var body: some Scene { …
alpennec
  • 1,864
  • 3
  • 18
  • 25
0
votes
0 answers

Load Core Data data (iOS and swiftUI)

I'm developing an app, and I need save data, so im using Core Data, and unfortunately in not a Core Data expert When I run the app for the first time, it works and saves the data (I checked the *.sqlit file), but if re-run the app give me this…
0
votes
1 answer

ProgressView in SwiftUI 2.0 (How to display the ProgressView during an operation)

I'm trying to show a ProgressView while something is being processed, and the app busy. in this exemple during the for import SwiftUI struct ContentView: View { @State var isLoading:Bool = false var body: some View { ZStack{ if…
GaF
  • 101
  • 2
  • 5
0
votes
1 answer

change a value inside a swiftUI view based in a change made in his child

I have this code: Main view import SwiftUI struct ContentView: View { @EnvironmentObject var data:Pessoa var body: some View { NavigationView{ VStack{ NavigationLink(destination:view2(data:…
GaF
  • 101
  • 2
  • 5
0
votes
1 answer

WKWebView detect login page change or re-direction

I have a swift WKWebView app with user authentication, the app allows users to register their devices by collecting the device's vendor id. When a user runs the mobile app, it will check if the mobile device is registered then validates the login…
Alan
  • 59
  • 6
0
votes
1 answer

SwiftUI @EnvironmentObject no ObservableObject of type error

I am getting the error Fatal error: No ObservableObject of type LoginResponse found. A View.environmentObject(_:) for LoginResponse may be missing as an ancestor of this view. I have passed the environment object to all the subviews of…
Abhi Ram
  • 33
  • 5