以下代码是从WWDC中间级Swift演讲的示例中推导出来的。我所尝试做的是从某种API获取的键-属性列表初始化一个模型类。
class Movie {
var title: String
init(title: String) {
self.title = title
}
}
func movieFromDictionary(dict: Dictionary<String, AnyObject>) -> Movie? {
switch dict["title"] {
case .Some(let movieTitle as String):
return Movie(title: movieTitle)
default:
return nil
}
}
当我尝试编译这些代码时,出现如下错误:
Bitcast requires both operands to be pointer or neither
%38 = bitcast i8* %37 to %SS, !dbg !161
Invalid operand types for ICmp instruction
%39 = icmp ne %SS %38, null, !dbg !161
PHI nodes must have at least one entry. If the block is dead, the PHI should be removed!
%42 = phi i64 , !dbg !161
PHI node operands are not the same type as the result!
%41 = phi i8* [ %38, %34 ], !dbg !161
LLVM ERROR: Broken function found, compilation aborted!
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1
有趣的是编辑器似乎对代码没有问题。这是编译器bug还是代码有问题?