How can I update the map after I click on an element in swiftUI? [closed] - swift

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 19 hours ago.
Improve this question
I am trying to develop an app that shows a trip on a map from a list of trips.
I have a list of trips in a bottom sheet and when I click on one of these I would like to update the map showing the information of the trip (the tripPoints on the map).
struct Trip {
let id: String
let tripPoints: [TripPoints]
}
struct TripPoints {
let id: String
let latitude: CLLocationDegrees
let longitude: CLLocationDegrees
}
I tried to use a variable selectedTrip that I update everytime i click on one of the trip, but the map doesn't update.

Related

Checking the entered data for correctness swift [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
How can I make a check for the correctness of the entered data?
For example, the user needs to enter a digit, and until this is done, the program will not skip it further
In my case, you need to make sure that the user entered an integer, and not a string, double, etc.
Just create an infinite loop. If your read is successful break it. Something like:
while true {
if let line = readLine(), let value = Int(line) {
print("value", value)
break
}
}

How to fix button clicked not updating but others do [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm making a math game. Every time I click a button a new question should appear with different results to choose from.
However every time I click the button which I think is the result it doesn't update the text but the others do.
See github: https://github.com/Combii/BrainTrainerSwift
Use UIButton.setTitle(, for:) method. I suggest you to change code in ViewController.swift:
func setNumbers(numberDic: Dictionary<String, Int>) {
let btns = [bt1, bt2, bt3, bt4]
UIView.performWithoutAnimation {
for (position, number) in numberDic {
btns[(Int(position) ?? 0) - 1]?.setTitle(String(number), for: .normal)
}
}
}

Is there a way to pass a variable after 5 seconds? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm creating a desktop app with Swift and I need to pass a stop boolean after 5 seconds. How do I do this?
You can use asyncAfter to create an async delay. After the 5.0 seconds you can do what you want.
var stop: Bool = false
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { // runs after 5.0 seconds
// pass your stop boolean here
}

How to use NSRegularExpression to separate youtube duration like "PT1H50M20S" [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a problem with youtube duration.
How to separate this string:
PT1H50M20S
to 1:50:20 with NSRegularExpression.
No need to use NSRegularExpression here, you can use NSCharacterSet instead.
let s = "PT1H50M20S"
s.componentsSeparatedByCharactersInSet(NSCharacterSet.letterCharacterSet())
.filter { $0 != "" }
.joinWithSeparator(":") // 1:50:20

How to write this if-condition for real? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How could I write this in real code?
if (!UIImageView with origin.x > 50.0) {
//Exlcude the imageview from whatever happens in this statement.
}
if (imageView.frame.origin.x <= 50.0) {
// The code in this block won't bother the image views
// with 'x > 50.0' anymore
}