I'm trying to take an IBOutlet of type UITextField, and use that variable in a function with let constants from another class... How would I go about dong this?
Example:
Class A
Import UIKit
class ViewController: UIViewController {
@IBOutlet weak var userInputTextField: UITextField!
@IBOutlet weak var labelToBeUpdated: UILabel!
}
Class B
Import Foundation
class Data {
let x = 10
let y = 100
}
I would like to take the userInputTextField in Class A and multiply it by x in Class B, then divide it by y in Class B... (userInput * x) / y
Thanks
Actually you can't multiply IBOutlet
s like text fields ;-)
Data
Int
and do the math by accessing Data
's properties.let data = Data()
if let userInput = Int(userInputTextField.text) {
let result = (userInput * data.x) / data.y
}