pableiros
pableiros

Reputation: 16032

Swift 3 - How to append NSMutableArray objects to another NSMutableArray

I wan to append objects from a NSMutablArray to another NSMutableArray on Swift 3 but I can't achieve that.

This is what I tried to do first:

mutableArray.addObjects(from: anotherMutableArray)

And I got this error:

Cannot convert value of type 'NSMutableArray?' to expected argument type '[Any]'

Then I tried this:

mutableArray.addObjects(from: anotherMutableArray as [Any])

And I got this error:

Cannot convert value of type 'NSMutableArray?' to type '[Any]' in coercion

How can I append objects from a NSMutableArray to another NSMutableArray on Swift 3?

Upvotes: 2

Views: 4469

Answers (1)

rmaddy
rmaddy

Reputation: 318794

You need to cast the NSMutableArray to a Swift array of AnyObject, not Any.

mutableArray.addObjects(from: anotherMutableArray as [AnyObject])

Upvotes: 5

Related Questions