I'm just learning Swift, I created this starter project that needs UIKit, but whenever I run the code I get the following error:
"Cannot find 'ContentView' in scope in Swift
And here's the code:
import UIKit
class ViewController: UIViewController {
private let imageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.backgroundColor = .white
return imageView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemPink
}
}
You might need to clean the Build folder, ie, use the keyboard shortcut Shift + Command + K or via the Menu “Product > Clean Build Folder”
You might need to restart Xcode.
You might need to restart your Mac
or
Are you loading the viewcontroller in AppDelegate/SceneDelegete manulay?
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
return true
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.