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 trialMartin Foldyna
10,359 PointsSwift index error
I'm getting error like this 'fatal error: Array index out of range'.
Here is my code:
init (index: Int) {
let brandsLibrary = BrandsLibrary().library
let playlistDictionary = brandsLibrary[index]
brand = playlistDictionary ["brand"] as! String!
clas = playlistDictionary["class"] as! String!
headquaters = playlistDictionary["headquaters"] as! String!
models += playlistDictionary["models"] as! [String]
}
Can somebody please help me how to get rid of this error?
Martin Foldyna
10,359 PointsBrendan Whiting unfortunately that's not it, but thanks for your help :)
Martin Foldyna
10,359 PointsBrendan Whiting unfortunately that's not it, but thanks for your help :)
1 Answer
Stephen Whitfield
16,771 Points"index out of range" means you are trying to access an item in your array that is outside the bounds of the array. I.e., if you are trying to access item 6 of an array that only holds 4 items, your app will crash because the array doesn't hold 6 items.
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 Pointsthere's an extra space between playlistDictionary and ["brand"]. maybe that''s it