Checking the entered data for correctness swift [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 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
}
}

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.

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)
}
}
}

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

Unable to set member variable [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 8 years ago.
Improve this question
Very strange issue.
I have the following code:
NSDictionary* notificationUserInfo = [pNotification userInfo];
NSManagedObject* newShoppingFilter = [notificationUserInfo valueForKey:#"shoppingListFilter"];
self.shoppingListFilter = newShoppingFilter;
NSLog(#"%# tapped", [newShoppingFilter valueForKey:#"name"]);
For some reason the self.shoppingListFilter = newShoppingFilter is not setting the variable.
I assume that this is some issue with not initializing the self.shoppingListFilter variable in some way but I cannot figure this out. The NSLog shows the right output, newShoppingFilter is not null but self.shoppingListFilter is.
Any help is appreciated.
I bet newShoppingFilter is nil. Most likely, there is no key "shoppingListFilter" in the notification user info dictionary.
Set a breakpoint at the line that assigns a value to self.shoppingListFilter and check the value of newShoppingFilter. Also display the entire contents of notificationUserInfo.
Post the code that creates the user info dictionary and passes it into the notification that you are posting. That would help track down the problem.

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
}