dimanche 1 février 2015

Float if statement returns error with || in swift

So here is my if statement:



if !DAGNViewControllerInstance.DValueVar<=5 || !DAGNViewControllerInstance.DValueVar>=1 || !DAGNViewControllerInstance.AValueVar<=6 || !DAGNViewControllerInstance.AValueVar>=2 || !DAGNViewControllerInstance.GValueVar<=3 || !DAGNViewControllerInstance.GValueVar>=2 || !DAGNViewControllerInstance.NValueVar<=3 || !DAGNViewControllerInstance.NValueVar>=1 || !DAGNViewControllerInstance.TValueVar<=9999 || !DAGNViewControllerInstance.TValueVar>=1 {

self.ErrorField.text = "One or more values are not in range!"
}


This if statement checks a variable to see if it is in range or not. But whenever I try to build the code I get an error from this if statement.


Swift Compiler Error Cannot Invoke '||' with an argument list of type '($T88, $T96)'


The ValueVars are floats. The DAGNViewControllerInstance is a instance of this UIViewController subclass:



import UIKit
extension String {
var floatValue: Float {
return (self as NSString).floatValue
}
}
class DAGNViewController: UIViewController {
@IBOutlet weak var DValue: UITextField!
@IBOutlet weak var AValue: UITextField!
@IBOutlet weak var GValue: UITextField!
@IBOutlet weak var NValue: UITextField!
@IBOutlet weak var TValue: UITextField!
var DValueVar: Float = Float()
var AValueVar: Float = Float()
var GValueVar: Float = Float()
var NValueVar: Float = Float()
var TValueVar: Float = Float()

@IBAction func GOButtonPressed(sender: UIButton) {
DValueVar = DValue.text.floatValue
AValueVar = AValue.text.floatValue
GValueVar = GValue.text.floatValue
NValueVar = NValue.text.floatValue
TValueVar = NValue.text.floatValue
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}


The Value IBOutlets are linked to UITextFields. The if statement is in another UIViewController subclass which is the custom class of a UIView in the storyboard which has a label that I want to display the error message.


Does anyone know why I get the error, and or how to fix it?


Aucun commentaire:

Enregistrer un commentaire