Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

kirstie perez
312 PointsIts says: swift_lint.swift:12:13: error: 'Int' does not have a member named 'subscript' println(numbers.count[index])
It says: swift_lint.swift:12:13: error: 'Int' does not have a member named 'subscript' println(numbers.count[index])
Can you please tell me what that means and how i can fix it?
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var index = 0
while index < numbers.count{
println(numbers.count[index])
index++
}
1 Answer

Chris Shaw
26,662 PointsHi Kirstie,
The problem lies with the below code.
println(numbers.count[index])
Here you're calling numbers.count
which doesn't support sub-scripting because it returns an value of the type Int
, you simply need to omit .count
and your code will work as expected.
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var index = 0
while index < numbers.count{
println(numbers[index])
index++
}
Happy coding!
kirstie perez
312 Pointskirstie perez
312 PointsThanks.
Chris Shaw
26,662 PointsChris Shaw
26,662 PointsYou're welcome.