in swift assert(0) 无法将 Int 类型的值转换为预期的参数类型 Bool
in swift assert(0) Cannot convert value of type Int to expected argument type Bool
我正在将 objective -C 翻译成 swift,但是当我在 swift 中写入 assert(0) 时出现错误,错误消息是 "in swift assert(0) Cannot convert value of type Int to expected argument type Bool "
我的代码在 objective -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;
}
并翻译成 swift :
switch UIApplication.shared.applicationState {
case .active:
statusStr += "foreground"
case .inactive:
statusStr += "inactive"
case .background:
statusStr += "background"
default:
assert(0)
break
}
我不知道 swift 中的 0 是 assert(true)
还是 assert(false)
。
提前致谢。
因为OC弱类型语言,它可以自动将0翻译成false,所以在assert中,可以是运行,但是swift是强类型语言,所以你应该使用assert(false ) 或者你应该自己翻译
我正在将 objective -C 翻译成 swift,但是当我在 swift 中写入 assert(0) 时出现错误,错误消息是 "in swift assert(0) Cannot convert value of type Int to expected argument type Bool "
我的代码在 objective -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;
}
并翻译成 swift :
switch UIApplication.shared.applicationState {
case .active:
statusStr += "foreground"
case .inactive:
statusStr += "inactive"
case .background:
statusStr += "background"
default:
assert(0)
break
}
我不知道 swift 中的 0 是 assert(true)
还是 assert(false)
。
提前致谢。
因为OC弱类型语言,它可以自动将0翻译成false,所以在assert中,可以是运行,但是swift是强类型语言,所以你应该使用assert(false ) 或者你应该自己翻译