I have a with my textField. I have data form using textfields in my cocoa app. I use Realm as my DataBase. The only way I can get my data to load into the textFields from the Database is to use TableViews and call tableView.reloadData(). The job doesn't call for tableView so I must use textFields. To my knowledge there is no textField.reloadData() method to reload the data after the database has Synced and loaded the data from the cloud to the data model. Is there a way to reload textFields?
here is my code
import Cocoa
import RealmSwift
class PublisherViewController: NSViewController {
@IBOutlet weak var publisherName: NSTextField!
let realm = try! Realm()
var pubData : Results<Pub>?
override func viewDidLoad() {
super.viewDidLoad()
// Here is where textField.stringValues should load into the viewDidLoad
let theData = Pub()
theData.pubName = publisherName.stringValue
}
func save(pubData: Pub) {
do {
try realm.write {
}
} catch {
print("there was an error saving pubData \(error)")
}
}
@IBAction func savePublisher(_ sender: NSButton) {
let publisherData = Pub()
publisherData.pubName = publisherName.stringValue
save(pubData: publisherData)
}
}
Here is the data model
import Foundation
import RealmSwift
class Pub: Object {
@objc dynamic var pubName = "Work Please"
}