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
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)
})
})
Edit: Please see rintaro's answer for an explanation of why this happens.
When using enumerateObjects
with trailing closure,
there are two overloaded candidates for it:
enumerateObjects(_:)
enumerateObjects(options:using:)
(because options:
is defaulted)Currently, we need to disambiguate this.
If you want to use trailing closure syntax, here's the workaround:
assets.enumerateObjects(_:) { (object, count, stop) in
content.append(object)
}
This works because this is equivalent to
let unapplied = assets.enumerateObjects(_:)
unapplied { (object, count, stop) in
content.append(object)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With