以下のコードでわかるように、リスト配列は他の3つのレルム結果配列から結合されます。次に、セルごとに削除アクションを実装したいと思います。しかし、アプリはこれらの例外を返したので、誰かがこれを解決するのを手伝ってくれますか?. どうもありがとうございました。
class BookmarksVC: UIViewController,UITableViewDelegate,UITableViewDataSource {
var articleList: Results<DynamicObject>!
var documentList: Results<DynamicObject>!
var itArticleList: Results<DynamicObject>!
var list = [Any]()
var article: Any!
var searchBar:UISearchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 320, height: 20))
func loadDataAndUpdateUI() {
articleList = realm.dynamicObjects(NewsArticle.className())
documentList = realm.dynamicObjects(Documents.className())
itArticleList = realm.dynamicObjects(ITNewsArticle.className())
for article in articleList {
list.append(article)
}
for document in documentList {
list.append(document)
}
for itArticle in itArticleList{
list.append(itArticle)
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
print(list.count)
return list.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
article = list[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "bookmarkCell", for: indexPath) as! BookmarkCell
cell.configureCell(article:article)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .default, title: "Delete") { (deleteAction, indexPath) -> Void in
//Deletion will go here
let itemToBeDeleted = self.list[indexPath.row]
try! realm.write {
realm.delete(itemToBeDeleted as! Object)
}
}
return [deleteAction]
}
これらのオブジェクトを作成するためのコードも添付します。
func saveFavoriteArticle() {
try! realm.write {
realm.add(bookmarkItem!)
}
print(realm.dynamicObjects(NewsArticle.className()))
}
//Same code for 2 remaining objects