0

In hopes of writing more readable code, I am trying to employ guard statements where applicable to check for the right conditions first. However, I am encountering compile time errors.

Here is my code:

//guard statements
//guards provide early exits or breaks, placing the error handler code near the conditions.
//Variables are in the same scope as the guard statement
func testGuard(testVar: String?) {
    guard let x = testVar where x.count > 2 else {
        print("failure")
        return
    }
}

Here is the error I'm getting:

MyPlayground.playground:511:35: error: 'count' is unavailable: there is no universally good answer, see the documentation comment for discussion guard let x = testVar where x.count > 2 else { ^~~~~

Swift.String:114:16: note: 'count' has been explicitly marked unavailable here public var count: Int { get } ^

Govind Rai
  • 14,406
  • 9
  • 72
  • 83

0 Answers0