Post

Replies

Boosts

Views

Activity

Reply to Notification Center Help
My common ancestor VC is connected to my HdVC through a segue and my FaVC through a bar button item and is held by a container nav controller.  Thanks for trying. So, something like this? container nav controller | common ancestor VC ---------- HdVC ---------------- FaVC segue bar button item
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Run something before another thing
I want you to understand that I am still really learning. No problem. Everyone is learning something everyday. One thing I want you to understand is you have no need to pretend you knew everything. You can ask when you find some terms you do not know. You just need to clarify what you do not know.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Run something before another thing
Yes here you go: Thanks for showing your code. But your viewDidLoad() and viewWillAppear(_:) are modified from what I have shown, breaking the basic principle: Do the next thing inside the completion handler. If you have done any changes breaking this principle, your code would never work as expected. Or do you still not understand what completion handler means?  I have not had the time to figure out what's wrong using breakpoints. I guess you just need time to learn it, or your Xcode is broken. Pleas tell me when you fix the issue and are ready to use breakpoints. One more, did you yourself write the code you have shown to me? The replies from you makes me feel as if you do not understand any parts of your code.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Run something before another thing
Here you go: Thanks. But as far as I checked, there are no significant difference than the example code I have shown. Can you show viewDidLoad() and viewWillAppear(_:)?  I don't know what they do or how to use them. Better learn it. Xcode Help page is really helpful. Add breakpoints to your code - https://help.apple.com/xcode/mac/current/#/dev9a374afc9.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Run something before another thing
What will 120 do? As I wrote, When communication is unstable, asynchronous call may take minutes. I am sure you have tested your super bad idea only on a usual communication status. There are many chances a simple communication would take tens of seconds. But you have no need to wait hours. If the communication was too bad and took more than two minutes, it might end with timeout error.  here is the function header: Thanks for showing the code. A little more, can you show the whole method including the call to setRandomJoke()?
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Run something before another thing
I figured out that for my case, I can just call it and then wait 0.6 seconds and call it again. To wait blank seconds use (replace 0.6 with the wanted amount):  That's a super bad idea. When communication is unstable, asynchronous call may take minutes. Do you want to replace 0.6 with 120?
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Copy-on-write types and SwiftUI
An interesting experiment. It seems as if SwiftUI creates a copy of @State variables when executing actions, so isKnownUniquelyReferenced(_:) would never return true. Until Apple provides us a way to implement CoW efficiently or updates the implementation of SwiftUI, you may need to use @StateObject instead of @State where efficiency would be a good concern. class ClassType: ObservableObject { init() { self.detail = Detail(values: []) } private var detail: Detail var values: [Int] { detail.values } func appendValue(_ value: Int) { objectWillChange.send() detail.values.append(value) } private final class Detail { init(values: [Int]) { self.values = values } deinit { print("calling deinit") } var values: [Int] } } struct ContentView: View { //@State var state = CowType() @StateObject var state = ClassType() var body: some View { Text("Hello, world! \(state.values.count)") .padding() .gesture(DragGesture().onChanged { _ in state.appendValue(Int.random(in: 1...100)) }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Unable to create list of string from json response
This code runs quite fine and shows 3 rows A, B and C below the title Remarks: import SwiftUI struct MyView: View { @State var currentFrResponse: CurrentFrResponse = CurrentFrResponse.createTestData() var body: some View { VStack{ Text("Remarks") .padding(.horizontal, 15) .font(.title2) if(currentFrResponse.remarks != nil){ List(currentFrResponse.remarks!, id:\.self){ currentRemark in VStack{ Text(currentRemark) .bold() .padding() }.padding() } } } } } struct MyView_Previews: PreviewProvider { static var previews: some View { MyView() } } extension CurrentFrResponse { static func createTestData() - CurrentFrResponse { var response = CurrentFrResponse() response.remarks = [ "A", "B", "C" ] return response } } So, it is clear that your problem exists in somewhere else not shown.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Append to Double
As already suggested, you should better hold the String representation of displayed digits and the Double value of it separately, but mutually dependent. In your case, computed property will work: struct ContentView: View { //... private var gridItemLayout = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] //@State var res: Double = 0 @State var digits: String = "0" var res: Double { get { digits.hasSuffix(".") ? Double(digits.dropLast()) ?? 0.0 : Double(digits) ?? 0.0 } nonmutating set { digits = String(format: "%.10g", newValue) //- May need better formatting } } @State var previousVar: Double = 0 //... var body: some View { VStack{ Spacer() HStack{ Spacer() Text("\(digits)") //- .font(.system(size: 50)) .bold() .padding() } //... switch numeri[i][j] { case Nums.AC: operat = Nums.AC; res = 0 case Nums.uguale: operat = Nums.uguale; res = final case Nums.somma: operat = Nums.somma; previousVar = res; res = 0 con = 0 case Nums.meno: operat = Nums.meno; previousVar = res; res = 0 con = 0 case Nums.divisione: operat = Nums.divisione; previousVar = res; res = 0 con = 0 case Nums.moltiplicazione: operat = Nums.moltiplicazione; previousVar = res; res = 0 con = 0 case Nums.percentuale: operat = Nums.percentuale; res = res / 100 case Nums.piùMeno: operat = Nums.piùMeno; //res = res * -1; if digits.hasPrefix("-") { digits = String(digits.dropFirst()) } else { digits = "-" + digits } con = 0 case Nums.virgola: operat = Nums.virgola; //res = Double(String(res) + ".") ?? 0 if !digits.contains(".") { digits += "." } default: //res = Double(numeri[i][j].rawValue) ?? 0 if digits == "0" { digits = numeri[i][j].rawValue } else { digits += numeri[i][j].rawValue } con += 1 } //... }.padding(2) } } You may need to improve many parts, but with this, you can append that number to res.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to How to call a SwiftUI button by its UUID?
This is the whole code. Thanks for showing the whole code. That helps me understand how your buttons are organized. (Unfortunately, using many, many, super many global variables making the code hard to read, and difficult to maintain or modify. I hope the next step of your exercise would be something to remove all the global variables and re-define them in some appropriate places. But that is another issue.) As far as I see your code, you have 8 buttons (embedded inside the subview Taste) their symbols are modified, independently their background are modified together to the same value Why don't you simply make knopf1...knopf8 an Array? struct ContentView: View { // Placeholder variables before the real symbols are written to the buttons @State private var knopf = Array(repeating: "questionmark", count: 8) @State private var abdeckFarbe = Color.blue var body: some View { VStack { Spacer() // First row HStack { // The struct "Taste" below is called several times to draw the buttons. ForEach(0..4) {i in Taste(symbol: knopf[i]) .background(abdeckFarbe) } } // Second row HStack { ForEach(4..8) {i in Taste(symbol: knopf[i]) .background(abdeckFarbe) } } Spacer() // The cards are mixed. Button(action: { // Initialising the routine to re-mix the card with every tap on this button. knopf = Array(repeating: "questionmark", count: 8) bilder = ["moon", "moon", "house", "house", "sunset", "sunset", "cloud", "cloud"] abdeckFarbe = Color.orange knopf = bilder.shuffled() //↓Are these really needed to be kept in global variables? bilder = [] anzahl = 0 }, label: { Text("Mischen") }) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21