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 Collections and Control Flow Introduction to Collections Adding Items to Arrays

drew s
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
drew s
Python Development Techdegree Graduate 19,491 Points

let zipCode: Int = 07083 result: 7083 Can someone explain to me why index 0 is not appearing to result

Can someone explain to me why index 0 is not appearing when you call the constant variable? I tried adding another number 1, in this case 1 is the index 0 and it shows up when you call the variable.

3 Answers

Addison Francisco
Addison Francisco
9,561 Points

First of all, if you are trying to create an array, your declaration is incorrect. In your declaration, you are creating a variable of type Int with a value of 07083, which is not a valid Integer (whole number) value; You cannot have a leading zero in an integer. The compiler will remove it. If you are trying to create an array of the numbers that comprise a zip code, you could do it like so

let zipCode: [Int] = [0, 7, 0, 8, 3]

Second, if you are creating an array of zip codes and they require a leading zero, you can use a String type.

let zipCodes: [String] = ["07083", "07082", "07081"]

Hope this helps.

drew s
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
drew s
Python Development Techdegree Graduate 19,491 Points

//Int I want this output: 07083

//array Not this output: [0 7 0 8 3] //brackets look ugly

So I just did this:

let zipCode:Int = 7083
"\(0)\(zipCode)"
Addison Francisco
Addison Francisco
9,561 Points

What was the problem it asked you to solve? Can you link to it or copy and paste the question?