mcry416
mcry416

Reputation: 3

Xcode Cannot find type 'HomeView' in scope

Xcode could't find custom UIView class. And if I try to make a simple class like a model it will work normally, but Xcode aslo can't completion code.

This is ViewController:

import UIKit

class HomeViewController: UIViewController {
    
    var hView: HomeView!
    var testModel: TestModel!

    private func initView(){
        self.view.backgroundColor = UIColor.gray
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        initView()
    }

}

And this is custom class:

import Foundation
import UIKit
import SnapKit

class AboutView: UIView{
    
    var rootOfTop: UIImageView!
    var searchBar: UISearchBar!
    var messaageButton: UIButton!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        installRootOfTop()
        installSearchBar()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - Install widget.
    private func installRootOfTop(){
        rootOfTop = UIImageView()
            // ...
        self.addSubview(rootOfTop)
        
        rootOfTop.snp.makeConstraints{ 
            // ...
        }
    }
    
    private func installSearchBar(){
        searchBar = UISearchBar()
            // ...
        self.rootOfTop.addSubview(searchBar)
        
        searchBar.snp.makeConstraints{ 
            //...
        }
    }
    
} ```[enter image description here][1]


  [1]: https://i.sstatic.net/zfxZK.jpg

By the way, if I create a new project it also work abnormal, but previous project work normally.
I suspect it's because Xcode temp, but i can't find the project's temp, also i think it's third base, but the new project work abnormal as the same.

Upvotes: 0

Views: 2772

Answers (1)

Erakk
Erakk

Reputation: 922

Is that the content of your HomeView.swift file? If true, your class name is wrong.

The file name and the class name don't match for HomeView.swift. You are declaring an AboutView class inside it, that's why Xcode can't find it.

Upvotes: 1

Related Questions