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 Dictionary causing indexing issues in Xcode 6.1.1

In my own project, I've created a Struct and designed in in a similar way to the MusicLibrary Struct in the Playlist Browser project.

The dictionary contains an array of 20 different entries.

Example code

struct TeamInfoLibrary {
var teams = [
        [
            "name": "Arsenal",
            "stadiumImage": "",
            "teamColor": ["red": 239, "green": 1, "blue": 7, "alpha": 1.0],
            "fontColor": ["red": 255, "green": 255, "blue": 255, "alpha": 1.0]
        ],
        [
            "name": "Aston Villa",
            "stadiumImage": "",
            "teamColor": ["red": 148, "green": 190, "blue": 229, "alpha": 1.0],
            "fontColor": ["red": 122, "green": 0, "blue": 60, "alpha": 1.0]
        ],

/// Plus 18 more entries 

] ///close dictionary

}

Once the dictionary gets over 3/4 entries, Xcode seems to be indexing indefinitely and will not let me build the project. There are no errors, it simply seems to freeze and be forever stuck indexing the project.

Any help would be appreciated. Looking on Stack Overflow there are a few suggestions that it could be a bug in Xcode?

Seems to be an issue with 6 elements or more: http://stackoverflow.com/questions/26494082/xcode-6-1-indexing-cannot-be-slower-and-stuck-at-the-end?lq=1

Has anyone else encountered this behaviour? Stack Overflow is suggesting appends after 5 elements, although it doesn't seem the most efficient way to write this code?

1 Answer

Now resolved, see: http://stackoverflow.com/questions/28411298/swift-array-causing-indexing-issues-in-xcode-6-1-1

Swift was having difficulty inferring the type of the structure.

Adding var teams: [[String: AnyObject]] resolved the issue

Thank you for this! Had the same problem!