Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contextual type 'NSFastEnumeration' cannot be used with array literal

Tags:

ios

swift

swift3

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?

like image 902
WYS Avatar asked Oct 07 '16 10:10

WYS


1 Answers

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)
like image 85
OOPer Avatar answered Nov 11 '22 20:11

OOPer