Reference to member 'delegate' cannot be resolved without a contextual type

Im not sure why, but my tableView.delegate & tableView.data are returning errors "Reference to member 'delegate' cannot be resolved without a contextual type" "Reference to member 'dataSource' cannot be resolved without a contextual type" I've done everything around my code to see why I am getting these errors but I do not understand. My code is below

import UIKit

@MainActor class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

@IBOutlet weak var TableView: UITableView!
public var meals = [Meal]()
override func viewDidLoad() {
    super.viewDidLoad()
    fetchJSON {
    print("APICompleted")
        
}
    tableView.delegate = self //error// 
    tableView.dataSource = self //error// 
}



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return  meals.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    let cell = UITableViewCell(style: .subtitle , reuseIdentifier: nil)
    cell.textLabel?.text = meals[indexPath.row].strMeal.capitalized
    return cell
}


func fetchJSON(completed: @escaping () -> ()) {
    
    let jsonUrlString =  "https://www.themealdb.com/api/json/v1/1/filter.php?c=Beef"
    
    guard let url = URL(string: jsonUrlString) else {
        print("invalid url string lel")
        return
    }
    print("Select a meal to make today!")
    
    URLSession.shared.dataTask(with: url) { data, response, error in
        guard let data = data else {
            return
        }
        do {
            let decoder = JSONDecoder()
            let mealDetailResponse = try decoder.decode(MealDetailResponse.self, from: data)
            for meal in  mealDetailResponse.meals {
                print("The Meal is \(meal)")
                DispatchQueue.main.async {
                    completed()
                }
            }
        }catch {
            print(error)
        }
    }.resume()
}

}

You seem to have a mis-spelling:

@IBOutlet weak var TableView: UITableView!

should be:

@IBOutlet weak var tableView: UITableView!

...since you later refer to "tableView".

Did that fix it for you, @Wenh08?

Previous post plus:

This code is bizarre:

1. override func viewDidLoad() {
2.     super.viewDidLoad()
3.     fetchJSON {
4.     print("APICompleted")
5.         
6. }
7.     tableView.delegate = self //error// 
8.     tableView.dataSource = self //error// 
9. }

Line 6 (closing curly brace) should not be.

Reference to member 'delegate' cannot be resolved without a contextual type
 
 
Q