Ron Buencamino Ron Buencamino - 2 months ago 404
Swift Question

Swift 3 - PHFetchResult - enumerateObjects - Ambiguous use of 'enumerate objects'

Not so sure why I'm getting "Ambiguous use of 'enumerate objects' in Swift 3.

let collections = PHAssetCollection.fetchAssetCollections(with: .moment, subtype: .any, options: nil)

collections.enumerateObjects { (collection, start, stop) in
collection as! PHAssetCollection
let assets = PHAsset.fetchAssets(in: collection, options: nil)
assets.enumerateObjects({ (object, count, stop) in
content.append(object)
})

}


Any thoughts? This code was working fine in Swift 2.2

Answer

I have run into this a few times myself, and it appears to be an issue with Swift's trailing closure syntax. Including parentheses around the closure argument should do the trick:

collections.enumerateObjects({ (collection, start, stop) in
    collection as! PHAssetCollection
    let assets = PHAsset.fetchAssets(in: collection, options: nil)
    assets.enumerateObjects({ (object, count, stop) in
        content.append(object)
    })

})
Comments