Skip to content

Instantly share code, notes, and snippets.

@diskball
Created September 16, 2018 20:24
Show Gist options
  • Save diskball/e29a77889aab98ff31c3e7bfade559a1 to your computer and use it in GitHub Desktop.
Save diskball/e29a77889aab98ff31c3e7bfade559a1 to your computer and use it in GitHub Desktop.
LogsViewController class
//
// LogsViewController.swift
// Realm Logger
//
// Created by George Bafaloukas on 12/09/2018.
// Copyright © 2018 George Bafaloukas. All rights reserved.
//
import UIKit
class LogUITableViewCell: UITableViewCell {
@IBOutlet weak var logLabel: UILabel!
}
class LogsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var logsTableView: UITableView!
var realmLogger: RealmLogger?
var logsArray: [RealmLog]?
override func viewDidLoad() {
super.viewDidLoad()
if let logs = realmLogger?.realm?.objects(RealmLog.self) {
self.logsArray = Array(logs)
self.logsTableView.reloadData()
}
}
// MARK: - UITableViewDelegate, UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.logsArray?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "LogUITableViewCell", for: indexPath) as! LogUITableViewCell
cell.logLabel.text = self.logsArray?[indexPath.row].message
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment