Im getting the following warning variable 'isTaken' was written to, but never read
on the following code :
func textFieldShouldEndEditing(textField: UITextField) -> Bool {
var isTaken: Bool = false
if textField == usernameTxt { var query = PFQuery(className: "_User")
query = PFQuery(className: "_User")
query.whereKey("username", equalTo: usernameTxt.text!)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) in
if error == nil {
if (objects!.count > 0){
isTaken = true
}
} else {
print("Username is available. ")
}
} else {
print("error")
}
}
}
return true
}
why am I getting the warning and how do I do away with it?
As error says variable 'isTaken' was written to, but never read
means you are creating isTaken
instance and assigning a value to it but it never used.
Just eliminate the statements:
var isTaken: Bool = false
isTaken = true
Since the value is never used, defining and assigning to it accomplishes nothing.
Basically it's saying that isTaken is assigned a value, but it doesn't actually do anything in your code. You are never using it or checking it's value, so it's simply an warning saying that the variable is unnecessary.
If you actually are using isTaken and the compiler doesn't realize for some reason, you could probably just add another line right after
isTaken = true;
that just says
isTaken;
Or make isTaken global if you're using somewhere else in the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With