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
}
}