0
In swift...., how can i ask to the user for data?
What i mean, is..., how can i do something similar to scanf() from C or readln() from pascal, but in swift? For example: Import UIkit Var a,b,c: Int //here i want to ask to the user for a and b values c = a + b Print(c)
4 Réponses
+ 5
Depends from where you want to take input.
For console, you can use readLine() {as already told by others}
But when creating an app, you would hardly be using console to get your input.
There you can use UITextField for the same 👇
https://developer.apple.com/documentation/uikit/uitextfield
and yes
in both the cases, the input will be read in form of a string, you have to type case it to type Int in order to perform any operations like addition on them.
here is an example 👇
https://code.sololearn.com/cYT15bj9Cc5u/?ref=app
+ 3
Using readLine()
Check this : https://www.programiz.com/swift-programming/basic-input-output
+ 1
nice tysm, thats what i need. ty all