"class not found" 出现了,尽管我之前在另一个 viewController 中做过,但它不起作用

"class not found" shows up even though I did it before In another viewController but it doesn't work

我收到这条消息,很多时候我都在学习教程,它是完全相同的代码,但它说它是错误的,然后我关闭我的电脑,它会自行修复,这正常吗?我现在的问题是它“class 未找到”

我也移动了我的文件以使用 MVC,但它不允许我导入 UIKit,我必须将它从文件夹中删除,然后它才能工作enter image description here

尝试更改:

var color2: UIColor -> color2: UIColor?

因为你的变量color2不是可选的,所以你需要先初始化它。所以将其设置为可选或为其设置默认值。