You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Backing up and starting mostly over led me here...
EntityListSectionedTableVC [no loner REALLY a TavleViewController I guess] will sit beside and act as a selector for EntityDetailSectionedTableVC. I had that much working fine with JUST the default tableViews. Editing textFields in EntityDetailSectionedTableVC started retain cycle nightmares.
No Stroyboard. So no clear example found to indicate what I might be missing. .fromClass is as much as I have found to address it specifically. Guessing the HOW-TO section is missing some details or steps for the Storyboard free since going Storyboardless means handling a few things that normally just work? Or maybe something about the struct is causing problems? Any insights would be most appreciated. Thnx
// EntityListSectionedTableVC.swift
import UIKit
import GRDB
import OwlKit
classEntityListSectionedTableVC:UIViewController{ //, UISearchBarDelegate, UISearchResultsUpdating
privatevarentityListDirector:TableDirector?privatevarEntityObserver:TransactionObserver?overridefunc viewWillAppear(_ animated:Bool){
super.viewWillAppear(animated)
// Start observing the database
loadFromDB()}overridefunc viewWillDisappear(_ animated:Bool){
super.viewWillDisappear(animated)
// Stop observing the database
EntityObserver =nil}overridefunc didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}overridefunc viewDidLoad(){
super.viewDidLoad()letEntityListViewAdapter=TableCellAdapter<Entity,EntityListViewCell>()
// instead of load cell from storyboard it will be loaded by
// reading the root view inside the xib with the same name of the class
EntityListViewAdapter.reusableViewLoadSource =.fromClass
// optionally you can also set a custom id
EntityListViewAdapter.reusableViewIdentifier ="EntityListViewCell"
// configure...
EntityListViewAdapter.events.dequeue ={ ctx in
ctx.cell?.entity = ctx.element
}
entityListDirector?.registerCellAdapter(EntityListViewAdapter)
entityListDirector?.rowHeight =.explicit(44.0)
// Cannot convert value of type 'Entity.Type' to expected argument type '[ElementRepresentable]'
// let newTableSection = TableSection(id: "sectionId", elements: Entity, header: "\(Entity.count) Entities", footer: nil)
}func loadFromDB(){
EntityObserver =TableChangeObserver()EntityObserver?.observes(eventsOfKind:.delete(tableName:"Entity"))EntityObserver?.observes(eventsOfKind:.insert(tableName:"Entity"))varnamesInTable=[Entity]()do{try dbQueue.write{ db in
// adding an observer fires 2 delegate methods
// 1st - databaseWillCommit() throws .........
// 2nd - databaseDidCommit(_ db: Database) ...
db.add(transactionObserver: EntityObserver!, extent:.observerLifetime)
db.afterNextTransactionCommit{ _ inprint("db.afterNextTransactionCommit")do{try namesInTable =Entity.fetchAll(db, sql:"SELECT * FROM Entity")}catch{print("ERROR ---------- db.afterNextTransactionCommit -> try Entity.fetchOne(db, sql: 'SELECT * FROM Entity')")}}}}catch{print("ERROR ---------- try Entity.fetchOne(db, sql: 'SELECT * FROM Entity')")}print(" ---\tnamesInTable\t\(namesInTable)")}}
// Entity.swift
import GRDB
import OwlKit
structEntity{
// Prefer Int64 for auto-incremented database ids
varid:Int64?varnoteID:Int64?varcontactID:Int64?varentityType:Int64?varname:Stringvarcreated:Doublevarmodified:Double}
// MARK: - Persistence
// Turn Entity into a Codable Record.
// See https://github.com/groue/GRDB.swift/blob/master/README.md#records
extensionEntity:Codable,FetchableRecord,PersistableRecord,MutablePersistableRecord{privateenumColumns{staticletid=Column(CodingKeys.id)staticletnoteID=Column(CodingKeys.noteID)staticletcontactID=Column(CodingKeys.contactID)staticletentityType=Column(CodingKeys.entityType)staticletname=Column(CodingKeys.name)staticletcreated=Column(CodingKeys.created)staticletmodified=Column(CodingKeys.modified)}
// Update a Entity id after it has been inserted in the database.
mutatingfunc didInsert(with rowID:Int64, for column:String?){
id = rowID
}}
/// https://github.com/malcommac/Owl#3.1
extensionEntity:Equatable,ElementRepresentable{ //ElementRepresentable
vardifferenceIdentifier:String{return"\(self.name)_\(String(describing:self.id))"}func isContentEqual(to other:Differentiable)->Bool{
guard let other = other as?Entityelse{return false }return other ==self}func==(lhs:Entity, rhs:Entity)->Bool{
// add more compare para,eters if && when needed...id should suffice
return lhs.id == rhs.id
}}
// EntityListViewCell.swift
import GRDB
import OwlKit
/// https://github.com/malcommac/Owl#3.2
publicclassEntityListViewCell:UITableViewCell{ // ElementRepresentable
publicvardifferenceIdentifier:String{return"EntityListViewCell"}
// Define a property you set on adapter's dequeue event
varentity:Entity?{
didSet {
// setup your UI according with instance data
}}}
The text was updated successfully, but these errors were encountered:
Backing up and starting mostly over led me here...
EntityListSectionedTableVC [no loner REALLY a TavleViewController I guess] will sit beside and act as a selector for EntityDetailSectionedTableVC. I had that much working fine with JUST the default tableViews. Editing textFields in EntityDetailSectionedTableVC started retain cycle nightmares.
No Stroyboard. So no clear example found to indicate what I might be missing. .fromClass is as much as I have found to address it specifically. Guessing the HOW-TO section is missing some details or steps for the Storyboard free since going Storyboardless means handling a few things that normally just work? Or maybe something about the struct is causing problems? Any insights would be most appreciated. Thnx
// EntityListSectionedTableVC.swift
// Entity.swift
// EntityListViewCell.swift
The text was updated successfully, but these errors were encountered: