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

get value from Dictionnary in a tableView with an indexPath.row?

I'm trying to get info from a plist. Here's the struct :

Root
-Dictionary
--Dictionary
---String
---String
--Dictionary
---String
---String
--Dictionary
---String
---String

And a little sample of it :

<plist version="1.0">
<dict>
    <key>introduction</key>
    <dict>
        <key>gfx</key>
        <dict>
            <key>titre</key>
            <string>Introduction</string>
            <key>color</key>
            <string></string>
            <key>miniLogo</key>
            <string></string>
            <key>bigLogo</key>
            <string></string>
        </dict>
...

So basically I'm to get the string value from a dictionary nested in another dictionary.

The trick is, I want to use a tableView

So far I'm here :

let pathRoot = NSBundle.mainBundle().pathForResource("MyPLIST", ofType: "plist")

let rootRubrique = NSDictionary(contentsOfFile: pathRoot!)

I'm trying to get the info like that :

let rubriqueTitre = NSDictionary(contentsOfFile: pathRoot!)?.allKeys[indexPath.row].objectForKey("gfx")?.valueForKey("titre")

But maybe the problem is from the way I'm trying to screen that

label.text = imageRubrique! as! String
// And also tried :
label.text = "\(imageRubrique!)"

Also I tried to get other values, just to try. This is working for me :

let rubriqueIndex = NSDictionary(contentsOfFile: pathRoot!)?.allKeys[indexPath.row]
 label.text = rubriqueIndex as! String

I get the "introduction" with a lower case, the first one. But I don't want that value, I want the nested one ! I'm getting crazy!

After that, I'll have to find a way to sort my dictionary in the right order which seems to be another big problem…