Sometime I've got an issue in this function :
func getCurrentEvent(events: RealmSwift.List) -> Event? {
let curDate = Date()
let filtered = events.filter { event in
return (curDate >= event.start) && (curDate <= event.end)
}
if let firstEvent = filtered.first {
return firstEvent
}
return nil
}
Log:
#0 (null) in __exceptionPreprocess ()
#1 (null) in objc_exception_throw ()
#2 (null) in -[NSException raise] ()
#3 0x10238cf80 in throwRealmException(_:userInfo:) at realm-swift/RealmSwift/Util.swift:53
#4 0x10238cf80 in staticBridgeCast(fromObjectiveC:) at realm-swift/RealmSwift/Util.swift:132
#5 0x10231fdb8 in List.subscript.getter at realm-swift/RealmSwift/List.swift:73
#6 (null) in specialized List.subscript.read ()
#7 (null) in specialized protocol witness for Collection.subscript.read in conformance List ()
#8 (null) in specialized LazyFilterSequence<>.startIndex.getter ()
#9 (null) in specialized protocol witness for Collection.startIndex.getter in conformance <> LazyFilterSequence ()
#10 (null) in specialized Collection.first.getter ()
#11 (null) in mainView.getCurrentEvent(events:) ()
How can I secure this function to avoid this ?
thanks for your help