I'm trying to add an extension to PHFetchResult to pull the result objects out as a correctly typed array - and so far I can't figure out how to avoid the replication seen below. Aside from the type constraint the following extensions are identical. If I use PHObject as the constraint it would work, but the result would need to be cast to the more specific type...
extension PHFetchResult where ObjectType == PHAsset {
var objects: [ObjectType] {
var _objects: [ObjectType] = []
enumerateObjects { (object, _, _) in
_objects.append(object)
}
return _objects
}
}
extension PHFetchResult where ObjectType == PHCollection {
var objects: [ObjectType] {
var _objects: [ObjectType] = []
enumerateObjects { (object, _, _) in
_objects.append(object)
}
return _objects
}
}
extension PHFetchResult where ObjectType == PHAssetCollection {
var objects: [ObjectType] {
var _objects: [ObjectType] = []
enumerateObjects { (object, _, _) in
_objects.append(object)
}
return _objects
}
}