0

I have two arrays

var array1 = [Doc 1, Doc 2, Doc 3]
var array2 = [Part 1, Part 2, Part 3]

I want to put items in array2 in array1 at certain index(between Doc 1 and Doc 2) like following:

[Doc 1, Part 1, Part 2, Part 3, Doc 2, Doc 3]

I know how to put an array into another array at certain index. But I'm not familiar with this kind of case. Is there any builtin method I can use in Swift? I can make my own algorithm but would like to know first if there's any built method for this case.

1
  • You say "I know how to put an array into another array at certain index". Do you mean you want a function that says "insert items from array1 between items y and z in array2"? I don't think you'll find anything that specific in the standard library. Commented Jan 20, 2016 at 23:27

1 Answer 1

2

This should do the trick:

array1.insertContentsOf(array2, at: 1)
Sign up to request clarification or add additional context in comments.

Comments

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.