Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class BackupViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
- var rows:[String] = []
- var showFiles = true
- @IBOutlet weak var table: UITableView!
- override func viewDidLoad() {
- super.viewDidLoad()
- self.table.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
- self.table.dataSource = self
- self.table.delegate = self
- getFiles()
- // Do any additional setup after loading the view.
- }
- func getFiles() {
- let filemgr = FileManager.default
- let path = filemgr.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask).last
- do {
- rows = try filemgr.contentsOfDirectory(atPath: (path?.path)!)
- // process files
- } catch {
- print("Error while enumerating files")
- }
- /*for file in files {
- rows.append(file.absoluteString)
- }*/
- showFiles = true
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return rows.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell:UITableViewCell = self.table.dequeueReusableCell(withIdentifier: "cell") as! UITableViewCell
- cell.textLabel?.text = rows[indexPath.row]
- return cell
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
- }
- */
- }
Add Comment
Please, Sign In to add comment