-5

I want to make an if statement with an greater than symbol in it. When I type the code it gives me this error: ''<' is not a prefix unary operator'

This is my code:

 if messages.count == >75 {
        navigationItem.rightBarButtonItem?.isEnabled = true
    } else if messages.count == <75 {
        navigationItem.rightBarButtonItem?.isEnabled = false
    }

Hope someone can help!

top1402
  • 1
  • 3
  • 4
    Its `>`, `<`, `>=` and `<=` in Swift (as in many other programming languages). How did you come up with `== >75` ?? – Martin R Mar 25 '17 at 09:29
  • In the Swift language reference: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html#//apple_ref/doc/uid/TP40014097-CH6-ID70. – Martin R Mar 25 '17 at 09:32

1 Answers1

1

Leave out the ==:

 if messages.count > 75 {
     navigationItem.rightBarButtonItem?.isEnabled = true
 } else if messages.count < 75 {
     navigationItem.rightBarButtonItem?.isEnabled = false
 }

There's more than just ==, > and <:

  • A == B means A is equal to B
  • A != B means A is not equal to B
  • A > B means A is greater than B
  • A < B means A is less than B
  • A >= B means A is greater than or equal to B
  • A <= B means A is less than or equal to B

Check out the language docs here.

Fabian Lauer
  • 8,891
  • 4
  • 26
  • 35