Post

Replies

Boosts

Views

Activity

Reply to Problems Updating a View
That (kinda) Worked! I think it did work, but you now move on to different questions! Also, why can't I just put objectWillChange.send() in the Data class? That will send objectWillChange for the data object, not for the NFCReader object (which is what ContentView is observing).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Problems Updating a View
In NFCReader, the "data" that you are adding the new item to is not the same as the "data" in your ContentView. They are two separate objects. So the addition will never show up in your UI. You need to use a single "data", and pass it to wherever it is needed. For example... In ContentView, you could remove data, make NFCReader the StateObject, publish NFCReader's data, and refer to that data in your View.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Picker with Unexpected Results
Consider this: struct PickColorView: View { @State private var number1: Int = 4 @State private var number2: Int = 0 let range: ClosedRange<Int> = 0...20 let array: Array<Int> = [14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60] var body: some View { NavigationView { Form { Picker(selection: $number1, label: Text("Number1")) { ForEach(range, id: \.self) { number in Text("\(number)") } } .onChange(of: number1) { newNumber1 in print("newNumber1: \(newNumber1)") } Picker(selection: $number2, label: Text("Number2")) { ForEach(array, id: \.self) { number in Text("\(number)") } } .onChange(of: number2) { newNumber2 in print("newNumber2: \(newNumber2)") } } .navigationBarTitle("Settings") .navigationBarHidden(false) } .navigationViewStyle(StackNavigationViewStyle()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Problems Updating a View
That (kinda) Worked! I think it did work, but you now move on to different questions! Also, why can't I just put objectWillChange.send() in the Data class? That will send objectWillChange for the data object, not for the NFCReader object (which is what ContentView is observing).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Is it proper to add an extension to UIViewController class, or is there a preferred way of adding another method to an established Swift Class?
You are using an Extension to add functionality to an existing class (UIViewController) that you don't "own". This is exactly what Extension is for. A fuller explanation: https://www.hackingwithswift.com/quick-start/understanding-swift/when-should-you-use-extensions-in-swift
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to function doesnt return a value
The function cannot return the value retrieved by your dataTask, as the function returns before the dataTask finishes. The dataTask completion should set some value in the wider environment, or itself call a passed-in completion closure.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Problems Updating a View
In NFCReader, the "data" that you are adding the new item to is not the same as the "data" in your ContentView. They are two separate objects. So the addition will never show up in your UI. You need to use a single "data", and pass it to wherever it is needed. For example... In ContentView, you could remove data, make NFCReader the StateObject, publish NFCReader's data, and refer to that data in your View.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Picker with Unexpected Results
Consider this: struct PickColorView: View { @State private var number1: Int = 4 @State private var number2: Int = 0 let range: ClosedRange<Int> = 0...20 let array: Array<Int> = [14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60] var body: some View { NavigationView { Form { Picker(selection: $number1, label: Text("Number1")) { ForEach(range, id: \.self) { number in Text("\(number)") } } .onChange(of: number1) { newNumber1 in print("newNumber1: \(newNumber1)") } Picker(selection: $number2, label: Text("Number2")) { ForEach(array, id: \.self) { number in Text("\(number)") } } .onChange(of: number2) { newNumber2 in print("newNumber2: \(newNumber2)") } } .navigationBarTitle("Settings") .navigationBarHidden(false) } .navigationViewStyle(StackNavigationViewStyle()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22