I've been pulling my hair out for a couple of days, and could really use some help.
I've got a property defined like this:
@objcMembers class Account: Object {
dynamic var name = ""
When I load .name
with a literal, i.e.,
let newAccount = Account()
// newAccount.name = self.accountTextField.text!
newAccount.name = "John Brown"
newAccount.isCurrent = true
newAccount.highWaterBalance = 0.0
I get this:
acct.name is John Brown
acct.highWaterBalance is 0.0
acct.isCurrent is true
However, when I type "John Brown" into self.accountTextField
, and use this code:
let newAccount = Account()
newAccount.name = self.accountTextField.text!
// newAccount.name = "John Brown"
newAccount.isCurrent = true
newAccount.highWaterBalance = 0.0
I get this:
acct.name is
acct.highWaterBalance is 0.0
acct.isCurrent is true
I've searched all over SO, and thought I had a fix in @rmaddy's contribution to this question.
I thought I was doing it right, but I'm still getting a blank from the textField
.
Any help would be greatly appreciated!
Edit 1:
This code:
print("Johnny B Goode\n")
print ("\(self.accountTextField.text!)")
print("Johnny B Bad\n")
Prints this result:
Johnny B Goode
Johnny B Bad
Edit 2:
For full clarity, and maybe I should have mentioned this before, here is the IBAction
code that produces the alert in which self.accountTextField.text
is located:
@IBAction func addAccountButton(_ sender: Any) {
// Pop alert to add new account
let addAcctAlert = UIAlertController(title: "Create New Account", message: "Please name your new account", preferredStyle: UIAlertControllerStyle.alert)
addAcctAlert.addTextField { (accountTextField) in
accountTextField.placeholder = "Enter new account name"
accountTextField.keyboardType = .`default`
}
addAcctAlert.addAction(UIAlertAction(title: "Continue", style: UIAlertActionStyle.destructive, handler: { action in
// Create new Account with name, balance, isCurrent, save to disk
print("Johnny B Goode\n")
print ("\(self.accountTextField.text!)")
print("Johnny B Bad\n")
let newAccount = Account()
newAccount.name = self.accountTextField.text!
// newAccount.name = "John Brown"
newAccount.isCurrent = true
newAccount.highWaterBalance = 0.0
self.addCreatedAccount(thisAccount: newAccount)
}
))
addAcctAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
self.present(addAcctAlert, animated: true, completion: nil)
}
It really does appear that regardless of what I type in the textField
, it produces nothing. Is that possible?