Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift 2.0 Collections and Control Flow Introduction to Collections Working with Arrays

Wang Lei
Wang Lei
2,766 Points

Could you please help me on this coding challenge?

I have tried on X-code, the system doesn't allow adding Int item through + operator: for example: arrayOfInts=arrayOfInts+(8) I have tried insert Int item and it works.

arrays.swift
// Enter your code below
var arrayOfInts: [Int] = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts.insert (8, atIndex 7)

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

I have not looked at the challenge, but from what I see you are trying to add more ints into the array.

Here are some ways you can do this:

var arrayOfInts: [Int] = [1,2,3,4,5,6]

// If you want to add ONE int use this method.
arrayOfInts.append(7)

// If you want to add ONE int at an specific index, use this method.
arrayOfInts.insert (8, atIndex: 7)

// If you want to add MORE than ONE int, do it this way. 
// It will add the ints to the end of the array.
arrayOfInts += [9,10]

Good luck :)

Wang Lei
Wang Lei
2,766 Points

Thank you very much. problem solved. It seems I use the wrong brackets.