swift - 条件绑定的初始化程序必须具有 Optional 类型,而不是“AnimationView”
问题描述
这是什么意思?
条件绑定的初始化程序必须具有 Optional 类型,而不是“AnimationView”
一直在努力弄清楚我的意思以及如何解决它?任何帮助将不胜感激
override func viewDidLoad() {
super.viewDidLoad()
if let animationView = AnimationView(name: "breathing") {
animationView.frame = CGRect(x: 0, y: 0, width: 400, height: 400)
animationView.center = self.view.center
animationView.contentMode = .scaleAspectFill
view.addSubview(animationView)
animationView.play()
}
解决方案
该错误很明显AnimationView(name: "breathing")
不是可选的。
代替:
if let animationView = AnimationView(name: "breathing") {
和:
let animationView = AnimationView(name: "breathing")
推荐阅读
- c# - Xamarin Android:绑定套接字错误(机器不在网络上)
- python - 写入文本文件时更改python中嵌套for循环内的变量值
- php - 在wordpress中如何在另一个循环中获取post循环
- r - R - 来自大型数据框的唯一值
- graphql - Typescript GraphQL 等效于 EnumSet
- r - 带有闪亮的verbatimTextOutput的无效参数类型
- javascript - 将 Fingerprint2 结果保存在变量中
- php - 在 php 中的 cronjob 上找不到命令错误
- npm - 模块存在于 package.json 但在 firebase 上找不到
- javascript - 使用 unicode 标志的正则表达式在 IE 和 FF 中失败