     })
 
     let sorting: YapDB.View.Sorting = .ByObject({ (group, collection1, key1, object1, collection2, key2, object2) -> NSComparisonResult in
-        if let event1: Event = valueFromArchive(object1) {
-            if let event2: Event = valueFromArchive(object2) {
+        if  let event1 = Event.unarchive(object1),
+            let event2 = Event.unarchive(object2) {
                 return event1.date.compare(event2.date)
-            }
         }
         return .OrderedSame
     })

                return collection
            }

            if let event: Event = valueFromArchive(object) {
                return event.color.description
            }
        }

}

public func events(byColor: Bool = false, mappingBlock: YapDB.FetchConfiguration.MappingsConfigurationBlock? = .None) -> YapDB.FetchConfiguration {
    return YapDB.FetchConfiguration(fetch: events(byColor), block: mappingBlock)
}

public func events(byColor: Bool = false, mappingBlock: YapDB.FetchConfiguration.MappingsConfigurationBlock? = .None) -> Configuration<Event> {
    return Configuration(fetch: events(byColor), itemMapper: Event.unarchive)
}

public func eventsWithColor(color: Event.Color, byColor: Bool = false) -> YapDB.Fetch {

    let filtering: YapDB.Filter.Filtering = .ByObject({ (group, collection, key, object) -> Bool in
        if let event = Event.unarchive(object) {
            return event.color == color
        }
        return false
    })

    let filter = YapDB.Filter(name: "\(color) Events", parent: events(byColor), filtering: filtering, collections: [Event.collection])

    return .Filter(filter)
}
