Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we execute code through textfields in iOS?

Tags:

ios

swift

var hello = "sad"
var u = "\(hello)"
println(u) // it prints sad

@IBOutlet weak var myTextField: UITextField!
func textFieldShouldReturn(textField: UITextField) -> Bool {
   println(myTextField.text)
}

To the text field i pass "\(hello)", but i don't see the value in the log.

like image 947
Nitesh Agarwal Avatar asked Feb 27 '26 15:02

Nitesh Agarwal


2 Answers

short answer, no.

long answer, the (hello) is evaluated at compile time, and hence wont work at run time through a text field.

like image 174
Fonix Avatar answered Mar 01 '26 06:03

Fonix


No, this will of course not work. And it would be a serious security issue if it would.

At compile time the compiler detects those \() and compiles these strings to use string interpolation in the assembly/machine code. You can think of this as if the compiler would turn "Hello \(name)" into "Hello " + name.

At runtime these strings are just collections of characters for whose content nobody cares.

like image 45
idmean Avatar answered Mar 01 '26 05:03

idmean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!