Wiafe
Wiafe

Reputation: 84

Why is this guard statement throwing me an error?

So I'm following a tutorial form Lynda.com for making a iOS app with Swift and when I plug this line of code in, it's throwing me errors:

guard let text:String = addressBar.text else

The error I get is: Consecutive statements on line must be separated by ';'

Once I have Xcode fix it, these are the errors I get: Expected expression. Use of unresolved identifier 'guard'. Expression resolves to an unused function. Braced block of statements is an unused closure.

I'm really new to Xcode and Swift so any help would be awesome! Thanks!

Upvotes: 2

Views: 579

Answers (2)

dede.exe
dede.exe

Reputation: 1310

May be you are using a wrong version of Xcode(version 7.0)

Try it too:

Be certain you are using guard statement in the right conditions. E.g:

class AddressBar {
    var text: String? = ""
}

var addressBar = AddressBar()
addressBar.text = nil
//addressBar.text = "text"


func test() {
    guard let _text: String = addressBar.text else {
        print("Nothing")
        return
    }
    print("I reach this point")
}

test()

Upvotes: 0

Nurdin
Nurdin

Reputation: 23893

Because you using outdated xcode and swift language. Latest version is xcode 7 and swift 2.

https://developer.apple.com/xcode/

Upvotes: 0

Related Questions