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

}

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

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

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 = valueFromArchive(object) {
            return event.color == color
        }
        return false
    })

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

    return .Filter(filter)
}

    })

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