Is there a way to pass a variable after 5 seconds? [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 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
}

Related

How can I update the map after I click on an element in swiftUI? [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 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.

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 do I add 2 to my score every second, I'm new to Xcode btw [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 2 years ago.
Improve this question
Im making a clicker game as my first ever game and im working on making a few upgrades. The first upgrade is an auto clicker. I want it to add 2 to my variable money every second. I made a var called moneypersecond. I got it so moneypersecond is right and shows how much I should be getting per second but I just need to update my money every second.
You can use a timer to achieve what you want.
Declare a variable Timer:
var timer: Timer?
Start your auto-clicker (in viewDidLoad for example), by assigning a repeating timer that executes a function incrementMoney.
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(incrementMoney(_:)), userInfo: nil, repeats: true)
Here is your function incrementMoney:
#objc func incrementMoney(_ timer: Timer) {
moneyPerSecond += 2
// You can set a limit here and increment your timer, if money reaches 5000 for example.
}
Finally, when you are done, don't forget to invalidate your timer as follows:
timer?.invalidate()

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
}