简体   繁体   English

Swift 编译器错误:在范围内找不到变量

[英]Swift compiler error: cannot find variable in scope

I am facing a strange error when writing the simplest of swift programs in Xcode 12.0.1.在 Xcode 12.0.1 中编写最简单的 swift 程序时,我遇到了一个奇怪的错误。 在此处输入图像描述

It says that it can't find T1 in scope when it is very much in scope.它说当它在范围内时无法在范围内找到 T1。 I feel that it must be trivial to solve this problem, and I tried ⌘ + ⇧ + K and closed Xcode and reopened, but the problem persists.我觉得解决这个问题一定是微不足道的,我尝试了 ⌘ + ⇧ + K 并关闭 Xcode 并重新打开,但问题仍然存在。 Anyone knows how this can be solved?任何人都知道如何解决这个问题?

Sometimes there are ghost errors that seem to not go away, even when Xcode is closed and reopened, but are fixed by either changing the code then changing it back, or clicking build anyway and the build succeeds.有时,即使 Xcode 已关闭并重新打开,也存在似乎不是 go 的幽灵错误,但可以通过更改代码然后将其更改回来,或者单击构建并且构建成功来修复。

Otherwise, the color highlighting of T1 in the return doesn't match in the variable declaration.否则,返回中T1的颜色突出显示与变量声明中的不匹配。 That suggests name clashing.这表明名称冲突。 Are there any types or global variables called T1 , even if there's nothing else in your code maybe it's a built-in type or similar?是否有任何类型或名为T1全局变量,即使您的代码中没有其他内容,也许它是内置类型或类似类型? Try naming the variable differently.尝试以不同的方式命名变量。

I got the same error and was searching around, but couldn't find an answer to it so I'll share it here for others to find as well.我遇到了同样的错误,正在四处寻找,但找不到答案,所以我会在这里分享给其他人。 For my part, I was creating a view in a package and was referencing that view from an app.就我而言,我在 package 中创建了一个视图,并从应用程序中引用了该视图。

I got the Cannot find [Type] in scope and turns out I forgot to put the public attribute on the view struct.Cannot find [Type] in scope结果我忘记将public属性放在视图结构上。

what's the "put the public attribute on the view struct."什么是“将公共属性放在视图结构上”。 mean?意思?

I don't understand!我不明白!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM