ios 在 Swift 中使用 isKindOf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37855734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:25:06  来源:igfitidea点击:

Using isKindOf in Swift

iosswiftswift3foundation

提问by Wangdu Lin

I use Xcode 8.0 beta to test my app, but after it convert my code 2.2 to 3.0, came out many unsolved bugs. Below the demo, Xcode8.0 appear the error message

我使用 Xcode 8.0 beta 来测试我的应用程序,但是在将我的代码 2.2 转换为 3.0 之后,出现了许多未解决的错误。在demo下方,Xcode8.0出现错误信息

1. Expected "{" after "if" condition...

1.“if”条件后应为“{”...

    if annotation.isKindof: (MKUserLocation) {
        return nil
    } 

Second error is the map kit...I use iskind(of: MKUserLocation) still not work out, it will appear another error message

第二个错误是地图工具包...我使用 iskind(of: MKUserLocation) 仍然无法解决,它会出现另一个错误消息

2.Braced block of statements is an unused closure

2.Braced 语句块是一个未使用的闭包

    if annotation.isKindof: (MKUserLocation) {
        return nil
    }

3. Missing argument label 'of:' in call

3. 调用中缺少参数标签“of:”

    if annotation.isKind(of: MKUserLocation) {
        return nil
    }

回答by Sahil Kapoor

The substitute for isKindOfin Swift3is:

isKindOfin的替代品Swift3是:

if annotation is MKUserLocation {
    return nil
}