Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Adding Photo To Custom Album

Tags:

ios

swift

assets

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

like image 564
Allan Macatingrao Avatar asked Nov 23 '15 08:11

Allan Macatingrao


2 Answers

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)
like image 104
totocaster Avatar answered Sep 19 '22 15:09

totocaster


This should work with Swift 3

albumChangeRequest.addAssets([photoPlaceholder] as NSArray)

like image 21
Stanley Yong Avatar answered Sep 19 '22 15:09

Stanley Yong