My viewcontroller not conforming to protocol UITAbleViewDataSource despite using protocol functions

I'm new to swift and I keep getting the error:

Type 'LablesTableView' does not conform to protocol UITableViewDataSource

I'm not sure what I'm doing wrong:


//
//  LablesTableView.swift
//  testing_folders
//
//  Created by Amit on 7/13/18.
//  Copyright © 2018 Amit. All rights reserved.
//


import UIKit


class LablesTableView: UIViewController {
    
    var folderObjects : [LabelObject] = []
    
    @IBOutlet weak var TableView: UITableView! // TableView delegate is UIViewController?
    override func viewDidLoad() {
        super.viewDidLoad()
        let (folders, labels) = FoldersInDocumentsDirectory()
        folderObjects = createArray(folderPathArray: folders,labelsArray:  labels) //bunch of objects
        TableView.delegate = self
        TableView.dataSource = self
        
    }
    
    func FoldersInDocumentsDirectory()-> ([URL], [String]){
        // all folders
        var folderPathArray : [URL] = []
        var labelsArray : [String] = []
        
        let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) [0] as String
        
        do {
            let folders = try FileManager.default.contentsOfDirectory(atPath: documentsPath)
            for i in 0...folders.count-1 {
                let folderURL = URL(fileURLWithPath: documentsPath ).appendingPathComponent(folders[i])
                folderPathArray.append(folderURL)
                labelsArray.append(folders[i])
                
            }
        } catch {
            //...
        }
        return (folderPathArray, labelsArray)
    }


    
    func createArray(folderPathArray:[URL], labelsArray:[String]) -> [LabelObject]{
        //temp array will populate the TableViewCells
        var tempArray : [LabelObject] = []
        let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
        let nsUserDomainMask    = FileManager.SearchPathDomainMask.userDomainMask
        let paths               = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
        if let dirPath          = paths.first
        {
            let imageURL = URL(fileURLWithPath: dirPath).appendingPathComponent("/data/amit.jpeg")
        let image = UIImage(contentsOfFile:imageURL.path)
        //print(image)
        for i in 0...folderPathArray.count-1{
            tempArray.append(LabelObject(image: image!, title: labelsArray[i] ))
        }
        
      
    }


       return tempArray


}
    
}




extension LablesTableView: UITableViewDataSource,UITableViewDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return folderObjects.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let folder = folderObjects[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell") as! LabelCell
        cell.setFolders(folder: folder)
        return cell
        
    }
    
}

Accepted Reply

Xcode sometimes digs out ancient error messages. Forget it and try clean build.

If you have some errors elsewhere, you may need to fix them first.


As far as I checked, if other parts of your code is consistent with the code shown above, your code should compile without errors.

Replies

Xcode sometimes digs out ancient error messages. Forget it and try clean build.

If you have some errors elsewhere, you may need to fix them first.


As far as I checked, if other parts of your code is consistent with the code shown above, your code should compile without errors.

Ah. Thank you. I do have errors in other parts of the code which I'm trying to fix. what do you mean by clean build?

You can find a menu title named Product when your Xcode is active.

Open it and choose Clean. And then build as usual.

Sometimes you may need to Option-open the Product menu and choose Clean Build Folder... .