Swift switch case编译错误

Swift switch case编译错误,第1张

概述以下代码是WWDC中的中级 Swift谈话示例的派生.我要做的是从一个键属性列表初始化一个模型类,它来自某种API. class Movie { var title: String init(title: String) { self.title = title }}func movieFromDictionary(dict: Dictionary<String, An 以下代码是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 !161InvalID operand types for ICmp instruction  %39 = icmp ne %sS %38,null,!dbg !161PHI nodes must have at least one entry.  If the block is dead,the PHI should be removed!  %42 = phi i64,!dbg !161PHI node operands are not the same type as the result!  %41 = phi i8* [ %38,%34 ],!dbg !161LLVM ERROR: broken function found,compilation aborted!Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift Failed with exit code 1

有趣的是编辑器似乎对代码没问题.这是编译器错误还是代码有问题?

解决方法 我同意评论者这是一个编译器错误,你应该向苹果报告.但是,您也可以通过这种方式实现它,这更简单,应该可以正常工作:

func movIEFromDictionary(dict: Dictionary<String,AnyObject>) -> MovIE? {  if let Title = dict["Title"] as? String {    return MovIE(Title: Title)  }  else {    return nil  }}
总结

以上是内存溢出为你收集整理的Swift switch case编译错误全部内容,希望文章能够帮你解决Swift switch case编译错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/999815.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存