WYS
WYS

Reputation: 1647

Contextual type 'NSFastEnumeration' cannot be used with array literal

Swift 3, would you do this?

let changeRequest = PHAssetCollectionChangeRequest(...)
let fastEnumeration = NSArray(array: [PHObjectPlaceholder])
albumChangeRequest?.addAssets(fastEnumeration)

or this?

let changeRequest = PHAssetCollectionChangeRequest(...)
albumChangeRequest?.addAssets([PHObjectPlaceholder] as NSFastEnumeration)

and what is the difference?

Upvotes: 9

Views: 3149

Answers (1)

OOPer
OOPer

Reputation: 47886

As you have found (your code has some inconsistency and causes other errors, better update it), you cannot use as-casting to specify the type for Array literals as NSFastEnumeration.

You need to find a proper class which conforms to NSFastEnumeration, in your case it's NSArray.

Usually write something like this:

changeRequest?.addAssets([/* needs instances, not type...*/] as NSArray)

Upvotes: 13

Related Questions