[英]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.