<<错误类型>>奇怪的错误 [英] <<error type>> Strange Error

查看:35
本文介绍了<<错误类型>>奇怪的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到过 xcode 停止自动完成的情况,如果您尝试编写已定义的变量,xcode 会说 <<错误类型>>.

I have encountered a situation where xcode stops auto-completing and if you try to write a variable that already been defined xcode says << error type>>.

这是我的错误:

推荐答案

这通常表示您的代码当前无法编译.Swift 经常无法计算本身不正确的代码类型.在某些情况下,这是编译器中的错误.使用 AnyObject 可能会让编译器特别困惑,应该尽可能避免.在这种情况下,AnyObject 是必需的,但您应该尝试将其快速转换为特定类型.例如,如果您可以提供帮助,请不要返回 [AnyType].

Often this indicates that your code doesn't currently compile. Swift often has trouble computing types on code that itself isn't correct. In some cases it's a bug in the compiler. Use of AnyObject can be particularly confusing to the compiler, and should be avoided as much as possible. In this case, AnyObject is required, but you should try to get it converted to a specific type quickly. Don't return [AnyType] for instance if you can possibly help it.

但简短的回答是 Swift 编译器仍在不断发展,它不能总是在复杂情况下计算类型,尤其是在部分或(当前)不正确的代码上.

But the short answer is that the Swift compiler is still evolving, and it can't always work out types in complex situations, particularly on partial or (currently) incorrect code.

请注意,您将 var 用于许多应该是 let 的事情.除非您确实需要修改变量,否则您应该更喜欢 let.它可以帮助您防止多种错误,并且可以更轻松地处理编译器(因为变量可以更改的方式较少).

Note that you're using var for a lot of things that should be let. Unless you actually need to modify the variable, you should prefer let. It helps you prevent many kinds of bugs, and can be easier on the compiler to deal with (since the variable has fewer ways it can change).

这篇关于&lt;&lt;错误类型&gt;&gt;奇怪的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆