Не удается найти тип » » в области в файле расширения Swift 5.3

#swift #xcode12

#swift #xcode12

Вопрос:

Я пытаюсь использовать расширения в своем проекте с независимыми файлами, но у меня «Не удается найти тип» » в области видимости», когда я пытаюсь UIView создать экземпляр UImage , UITableViewDelegate , и т.д. классы в моем расширении, как я могу исправить эту ошибку?

введите описание изображения здесь

Это мой код:

 extension MenuView: UITableViewDelegate, UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return titleArray.count
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView()
        view.backgroundColor = UIColor.white
        
        let button = UIButton(type: .system)
        button.frame = CGRect(x: 0, y: 0, width: 344, height: 50)
        button.addTarget(self, action: #selector(handleExpandClose), for: .touchUpInside)
        button.tag = section
        view.addSubview(button)
        
        let titleLabel = UILabel()
        titleLabel.text = ((titleArray[section] as NSArray)[0] as! String)
        titleLabel.font = titleLabel.font.withSize(16)
        titleLabel.textColor = UIColor.black
        titleLabel.frame = CGRect(x: 40, y: 20, width: 80, height: 20)
        view.addSubview(titleLabel)
        
        let icon = UIImage(named: ((titleArray[section] as NSArray)[1] as! String))
        let iconImage = UIImageView(image: icon)
        iconImage.frame = CGRect(x:250, y:25, width: 15, height: 10)
        view.addSubview(iconImage)
        
        return view
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 50
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if !subtitleArray[section].isExpanded {
            return subtitleArray[section].names.count
        }
        
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MenuCell", for: indexPath) as! MenuTableViewCell
        cell.titleCell.text = ((subtitleArray[indexPath.section].names as NSArray)[indexPath.row] as! String)
        cell.iconCell.image = UIImage.init(named: ((iconArray[indexPath.section] as NSArray)[indexPath.row] ) as! String)
        return cell
    }
    
}
  

Комментарии:

1. Может быть, вы забыли import UIKit вверху каждого файла?

2. этот код — это просто мой код расширения, очевидно, что в моем файле есть import UIKit