Questions tagged [observableobject]

262 questions
0
votes
0 answers

Is it possible to present an UIAlertController in a SwiftUI class?

I have a class and i try to present an UIAlertController directly in it if there is an error. Is it possible to do that in SwiftUI? My code (obviously not working) : import Firebase import Combine class TestFirebaseAlertClass: ObservableObject { …
Flincorp
  • 751
  • 9
  • 22
0
votes
1 answer

How to select an item by a button or tapGesture in my SwiftUI List and transfer it to another view

In my app I´m needing two players (only 2 names/strings), selected from an array built in a List/ForEach SwiftUI-code, which are used in another view. What is the way to bring the name into a string for my Text(item)? Can I select two items out of…
0
votes
1 answer

How do you send values to other classes using ObservableObject in SwiftUI

Im trying to create a simple tip Calculator but i am having a problem once a user has added in the information in the app instead of calculating the tip, the function is returning as if there is an issue somewhere. Im trying to make it so that when…
Gino Sesia
  • 383
  • 2
  • 4
  • 14
0
votes
1 answer

Xamarin Forms List Row Values not being updated when Re-LoadingData?

I am creating a list of scanned items. Whenever an item is scanned it checks if it already exists and if it does it increases the quantity, otherwise it will be added as a new item in the list. When an item is added in the list the change is…
Frosty
  • 39
  • 1
  • 7
0
votes
1 answer

Metronome SwiftUI, Change timer interval whenever the @State var is changed

I'm building the a metronome with swiftUI I have a @State var that connect to a slider. @State private var period: Double Slider(value: period, in: 0.25...5, step: 0.25) Right now I can only reset the time interval if I restart the…
Linus
  • 69
  • 4
0
votes
1 answer

Binding @Binding / @State to the @Publisher to decouple VM and View Layer

I want to decouple my ViewModel and View layer to increase testability of my Views. Therefore, I want to keep my property states inside view and only init them as I needed. But I cannot initialize my @Binding or @States with @Published properties.…
OguzYuksel
  • 88
  • 6
0
votes
1 answer

A View.environmentObject(_:) for AppInformation may be missing as an ancestor of this view

So I'm currently getting to grips with swift and swiftui and have run into a problem with Observable objects. I want to be able to share the value of a variable over 2 different views so opted to use an Observable Object. The duration and interval…
0
votes
2 answers

@Published String Variable Not Updating View

My @Published string variable in Observableobejct does not update the Text somehow. Exact same codes works in different view, but I can't figure out why this isn't working in this view. When I searched Google all I figured out was about checking the…
S. Hwang
  • 71
  • 1
  • 12
0
votes
1 answer

Do I need "PreviewProvider" to use use @ObservedObject when building to a device SwiftUI

This is what my code is looking like: import SwiftUI struct dummy: View { var job: Job @ObservedObject var jobViewModel: JobViewModel var body: some View { Text("Placeholder for job details, will not exists in production,…
0
votes
1 answer

Converting SceneDelegate Enviromental Object to AppMain

Feel free to edit my title for better clarity. I am starting a new iOS project and am no longer using SceneDelegate/AppDelegate. My problem is I want my ObservableObject to be an Environmental Object for my entire project but am having trouble…
C. Skjerdal
  • 2,750
  • 3
  • 25
  • 50
0
votes
1 answer

@published not working with array of types, but works fine with single type

I am testing very simple code, having one class that’s confirming to @ObservableObject protocol, and that has two @Published property one that’s taking array of my custom type objects, and other is just a normal type of same class. I have two views…
Tushar Sharma
  • 2,839
  • 1
  • 16
  • 38
0
votes
1 answer

Load different data by ID in the same View

I want to load different data in the same View using an ObservableObject with an Index. As you can see in the simple demo example attached when I go through the views changing the id in order to load different data it works. But when in any point I…
0
votes
1 answer

SwiftUI: Update ObservableObject array in Detail TabView to update Main ListView

I am new to programming and SwiftUI so this will be basic. (this code is a combination of different ObservableObject tutorials I found so there are unnecessary/wrong steps, in fact, the whole thing might be wrong). Any help is greatly…
RachelS
  • 3
  • 2
0
votes
1 answer

How to bind a SwiftUI view to properties of an element in an array

I'm using MVVM architecture with SwiftUI. I'm trying to refactor my code to use ForEach() in my view to display a number of subviews that all have the same basic format, a string (asking a question) and a button to press to display a sheet to enter…
Kramer
  • 338
  • 2
  • 15
0
votes
1 answer

How to update ParentView after updating SubView @ObservedObject SwiftUI

This is a simple example for my case. I have a @ObservedObject viewModel (Object1), pass a property (Object2) to another view (View2) . Change value in View 2, and when i go back to View 1, i wish the value is updated too. What is the best…