Swift error: Could not find an overload for '==' that accepts the supplied arguments?

Swift error: Could not find an overload for '==' that accepts the supplied arguments?

实际上我正在检查我的代码中的互联网连接,但我收到一个奇怪的错误 "Could not find an overload for '==' that accepts the supplied arguments"

这是我的代码片段,

override func viewDidLoad() {
        super.viewDidLoad()

        checkkNetworkStatus()

        let requestURL = NSURL(string: "http://example")

        let request = NSURLRequest(URL: requestURL!)

        webView.loadRequest(request)

    }


func checkkNetworkStatus(){

        let networkChecking : Reachability = Reachability.reachabilityForInternetConnection()

        networkChecking.startNotifier()

        var status : NetworkStatus = networkChecking.currentReachabilityStatus()

        if (status == NotReachable)   ***//error***
        {
            // statement
        }

}

你的错误在于你的if语句:

if status == NotReachable

你必须这样重写:

if status == .NotReachable

或者这个:

if status == NetworkStatus.NotReachable

status 是一个枚举值,您可以通过我编写的两种方式之一访问枚举的不同属性。

如果你想了解更多关于枚举的知识,你应该check the docs.

你可以做到 if (status == .NotReachable)if (status == NetworkStatus.NotReachable).