mercredi 24 juin 2015

Populate table view from Struct

I have a Struct such as:

struct Test {
            var name: String?
            var value: Float?
            var isfavorite:String? 


    init(name: String, value: Float, favorite: String){

        self.name = name
        self.value = rawRate
        self.favorite = favorite
    }
}

And a String in wich I stored a string according to the Test Struct

var TestInformation = [String:Test]()

When I want to populate a tableview based on the content of TestInformation I get the following error:

[String : Test]' does not have a member named 'name'

Here is the line I use to populate the tableview:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

            cell.testlabel?.text =  TestInformation[indexPath.row].name
}

I don't understand what I am doing wrong, maybe someone point me to right direction.

Thank you :)

Edit :

I add information to testInformation by doing the following:

let testInformation =  [
    Test(name: "Foo1", value: 1.32, isfavorite: "favorite"),
    Test(name: "Foo2", value: 1.27, isfavorite: "favorite")]

See more ..

Aucun commentaire:

Enregistrer un commentaire