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

Passing data through prepare for segue

I'm trying to build an app where I have a tableViewController and using the prepareForSegue function to pass data to a static cell controller. below are my two model files. I'm kind of stuck because I don't really know what to do after I call the function. I would be grateful for anybody's help. Thank you.

// Initiaization class Topic{

var title: String
var description: String
var firstImage: String
var secondImage: String

init(title: String, description: String, firstImage: String, secondImage: String){
    self.title = title
    self.description = description
    self.firstImage = firstImage
    self.secondImage = secondImage

}

// Dictionary

struct Library { let miracles: [[String : AnyObject]] = [

    ["title": "Universe",
        "description": "this is laskhg shfglkjhfg",
        "firstImage": "universe",
        "secondImage": "pic"],
    ["title": "Speed of light",
        "description": "this is laskhg shfglkjhfg",
        "firstImage": "speedOfLight",
        "secondImage": "pic"],
    ["title": "seas",
        "description": "this is laskhg shfglkjhfg",
        "firstImage": "seas",
        "secondImage": "pic"],
    ["title": "Tectonics",
        "description": "this is laskhg shfglkjhfg",
        "firstImage": "view",
        "secondImage": "pic"],
    ["title": "Bees",
        "description": "this is laskhg shfglkjhfg",
        "firstImage": "bees",
        "secondImage": "pic"],
    ["title": "Atoms",
        "description": "this is laskhg shfglkjhfg",
        "firstImage": "beach",
        "secondImage": "pic"],
    ["title": "Cloud Seeding",
        "description": "this is laskhg shfglkjhfg",
        "firstImage": "beachmorning",
        "secondImage": "pic" 

] }

Do you mean you're trying to fill the static cells? Or are you trying to pass the data once you tap the cell to an alternate view controller. prepareForSegue is used to pass data from one controller to another, not from a data model to a controller.

For example if I had two screens, one a tableView and one a detailView, I would use prepareForSegue to pass the specific data from the cell to the detail view. If i wanted to fill the cell, however, I would just instantiate the data in the tableView controller with an array and fill the cells that way.

I would suggest, in either case, using a reusable cell as it's scalable if your data ever increases.

yes that's what I meant, I have a detail view controller with a reusable cell, and it is connected with another tableView with static cells, the first is displaying a photo, the second is displaying a smaller photo, the third is displaying text. Each cell with its own size.