Reputation:
I've been trying to make an if statment in swift that checks if a label equals the same text. Like this,
if splitLabel.text = 1.0 = true {
var tipTotal = percentage * Double((billAmount)!)
but I get the error Cannot assign to a literal value
This is in Swift with Xcode 7
Upvotes: 1
Views: 964
Reputation: 112857
There is some guesswork since there are two assignment operators (=
) in the statement.
splitLabel.text
) to a number (1.0
). They are not the same types so can not be compared.==
, not =
, the latter is the assignment operator.=
) in the statement.Probably you want something like:
if splitLabel.text == "1.0" {
Upvotes: 4
Reputation: 522
You try to assign "true", I think you made a typo there
Use this code instead
if splitLabel.text == "1.0" {
var tipTotal = percentage * Double((billAmount)!)
}
Upvotes: 0