我正在创建如下的Realm对象
import RealmSwift
class Item: Object {
@objc dynamic var ID = 0
@objc dynamic var notificationTitleString = ""
@objc dynamic var notificationBodyString = ""
@objc dynamic var notificationDateString = ""
@objc dynamic var notificationType = ""
@objc dynamic var notificationUrl = ""
@objc dynamic var notificationActivity = ""
@objc dynamic var notificationIsRead = ""
override static func primaryKey() -> String? {
return "ID"
}
}
我正在使用以下方法获取特定的物品类型
import UIKit
import RealmSwift
class DBManager {
private var database: Realm
static let sharedInstance = DBManager()
private init() {
database = try! Realm()
print(Realm.Configuration.defaultConfiguration.fileURL!)
}
func fetchNotificationType(type: String) -> Results<Item> {
let predicate = NSPredicate(format: "notificationType = %@", type)
let results : Results = database.objects(Item.self).filter(predicate)
return results
}
}
使用上面的fetchNotificationType方法,我可以得到一个对象,但是我希望所有对象都在一个查询中。我不知道该怎么做,这是我第一次尝试Realm。
我搜索了SO,但没有得到任何相关答案。