2

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?

1 Answer 1

5

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

mutableArray.addObjects(from: anotherMutableArray as [AnyObject])
Sign up to request clarification or add additional context in comments.

2 Comments

Now I get the error: Cannot convert value of type 'NSMutableArray?' to type '[AnyObject]' in coercion
Is your anotherMutableArray optional? Is so, you need to deal with it properly just like any optional.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.