Why the “Use of undeclared type UITableView” happened in Swift?

I am new to Swift. I created a second swift file call DeviceInfo.swift and add a UIViewcontroller in Main.storyboard.

I also add a UITableView in UIViewcontroller(DeviceInfo).

  • Complex query from Firebase
  • Swift: Terminating with uncaught exception of type NSException
  • Using Core Location in Apple WatchKit
  • “Warning: iPhone apps should include an armv6 architecture” even with build config set
  • Disable UIPageViewController bounce
  • PerformSelector may cause a leak - Better solution
  • But the error Use of undeclared type 'UITableView' show after I connect the UITableView to DeviceInfo.swift via command + left. The error show like the following.
    enter image description here


    1. Why the Use of undeclared type 'UITableView' happened ? How to solve it ?

    2. Show I connect the dataSource and delegate to UIViewcontroller(DeviceInfo)?

    Thanks in advance.

    3 Solutions Collect From Internet About “Why the “Use of undeclared type UITableView” happened in Swift?”

    1.import UIKit

    2.To connect delegate and dataSource,
    click the point and drag to your tableView.
    enter image description here

    You need to add import UIKit at the top of your file, in the area where you’ve already got import Foundation. Without UIKit imported, your object doesn’t know what a UITableView is.

    UITableView in in UIKit framework, you didn’t imported that. SO import UIKit.

    In your viewDidLod:

    self.tableView.dataSource = self;
    self.tableView.delegate = self;

    In your .h file you can do:

    @interface YourClassName : UIViewController<UITableViewDataSource,UITableViewDelegate>

    And make sure you connected the tableView with an IBOutlet.
    #import <UIKit/UIKit.h>