6

I'm trying to implement function that saves captured photo to custom album following this article.

But I encountered error in this line (see article and Apple sample code):

albumChangeRequest!.addAssets([assetPlaceholder])

Contextual type of NSFastEnumeration cannot be used as Array Literal

Community
  • 1
  • 1
Allan Macatingrao
  • 2,071
  • 1
  • 20
  • 28

2 Answers2

5

This is happening because signature of addAssets is:

func addAssets(_ assets: NSFastEnumeration)

What that means is that it expects collection that conforms to NSFastEnumeration of which Swift Array does not, but NSArray does. Thus, creating NSArray from your array of PHObjectPlaceholder object works fine.

let fastEnumeration = NSArray(array: [photo.placeholderForCreatedAsset!] as [PHObjectPlaceholder])
albumChangeRequest!.addAssets(fastEnumeration)
totocaster
  • 6,243
  • 5
  • 37
  • 46
5

This should work with Swift 3

albumChangeRequest.addAssets([photoPlaceholder] as NSArray)

Stanley Yong
  • 1,844
  • 1
  • 12
  • 7