Allan  Macatingrao
Allan Macatingrao

Reputation: 2101

Swift: Adding Photo To Custom Album

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

Upvotes: 6

Views: 2158

Answers (2)

Stanley Yong
Stanley Yong

Reputation: 2034

This should work with Swift 3

albumChangeRequest.addAssets([photoPlaceholder] as NSArray)

Upvotes: 5

totocaster
totocaster

Reputation: 6373

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)

Upvotes: 5

Related Questions