我在我的iOS应用程序中使用
Realm和Swift 3.我有以下代码
//Find all records for the day func findForToday<T: Object>() -> [T] { let predicate = NSPredicate(format: "date >= %@ and date <= %@",DateUtil.dayStart(),DateUtil.dayEnd()) return getRealm().objects(T.self).filter(predicate).map { $0 } }
其中T在这个上下文中是我的领域模型类,看起来像
class MyModel : Object { dynamic var id = 0 dynamic var date = NSDate() override class func primaryKey() -> String? { return "id" } }
我在运行时说得到例外
Terminating app due to uncaught exception 'RLMException',reason: 'Object type 'RealmSwiftObject' is not managed by the Realm. If using a custom `objectClasses` / `objectTypes` array in your configuration,add `RealmSwiftObject` to the list of `objectClasses` / `objectTypes`.'