简体   繁体   English

在swift assert(0)中不能将Int类型的值转换为预期的参数类型Bool

[英]in swift assert(0) Cannot convert value of type Int to expected argument type Bool

I am translating objective -C to swift, but I get error when I write assert(0) in swift, the error message is "in swift assert(0) Cannot convert value of type Int to expected argument type Bool " 我正在将目标-C转换为swift,但是在swift中写assert(0)时出现错误,错误消息是“在swift assert(0)中无法将Int类型的值转换为预期的参数类型Bool”

my code in objective -c: 我在目标-c中的代码:

switch ([[UIApplication sharedApplication] applicationState]) {
        case UIApplicationStateActive:
            [statusStr appendString:@"foreground"];
            break;
        case UIApplicationStateInactive:
            [statusStr appendString:@"inactive"];
            break;


        case UIApplicationStateBackground:
            [statusStr appendString:@"background"];
            break;

        default:
            assert(0);
            break;
    }

and translate in swift : 并迅速翻译:

 switch UIApplication.shared.applicationState {

            case .active:
                statusStr += "foreground"
            case .inactive:
                statusStr += "inactive"
            case .background:
                statusStr += "background"
            default:
                assert(0)
                break

            }

I don't know 0 mean in swift make it assert(true) or assert(false) . 我不知道0意味着迅速将其assert(true)assert(false)

Thanks in advance. 提前致谢。

由于OC弱类型语言,它可以自动将0转换为false,因此在assert中可以运行,但是swift是强类型语言,因此您应该使用assert(false)或自己翻译

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift 3.0无法将(_,_)-&gt;()类型的值转换为期望的参数类型&#39;ObjectsOrErrorBlock&#39; - Swift 3.0 cannot convert value of type (_, _)->() to Expected argument type 'ObjectsOrErrorBlock' Swift无法将CBPeripheral类型的值转换为预期的参数类型 - Swift Cannot convert value of type CBPeripheral to expected argument type 无法将类型的值转换为预期的参数类型 - Cannot convert value of type to expected argument type 无法转换“范围”类型的值<Int> ?&#39; 到预期的参数类型 &#39;Range<String.Index> ? - Cannot convert value of type 'Range<Int>?' to expected argument type 'Range<String.Index>? 在Swift 2.0中无法将类型&#39;int&#39;转换为预期的类型NSTimeInterval - Cannot convert the type 'int' to expected type NSTimeInterval in swift 2.0 无法将Float类型的值转换为预期参数类型NSNumber - Cannot convert value of type Float to expected argument type NSNumber 无法将类型“(Void)-&gt;()”的值转换为预期的参数类型“()-&gt; Void” - Cannot convert value of type '(Void) -> ()' to expected argument type '() -> Void' 无法将“NSArray.Element”类型的值转换为预期参数 - Cannot convert value of type 'NSArray.Element' to expected argument 无法转换类型的值-Swift - Cannot convert value of type - Swift 无法将“NSNotification.Name”类型的值转换为预期的参数类型“NSKeyValueObservingOptions” - Cannot convert value of type 'NSNotification.Name' to expected argument type 'NSKeyValueObservingOptions'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM