我喜欢 Swift,但它的数字类型转换怪癖开始让我发疯......为什么下面的代码会导致LogLevel is not convertible to UInt8 error
(在 if 语句中)?
import Foundation;
enum LogLevel : Int
{
case System = 0;
case Trace = 1;
case Debug = 2;
case Info = 3;
case Notice = 4;
case Warn = 5;
case Error = 6;
case Fatal = 7;
}
class Log
{
struct Static
{
static var enabled:Bool = true;
static var filterLevel:LogLevel = LogLevel.System;
}
public class func trace(data:AnyObject!)
{
if (Static.filterLevel > LogLevel.Trace) {return;}
println("\(data)");
}
}
Int 类型的 LogLevel 毕竟应该等于 Int 类型的 LogLevel。