Creating a Model

The M in MVC

The ideas behind MVC are pretty straight forward. You call a database. The Data is returned as JSON formatted text. The JSON is parsed, and fed into your Custom UITableViewCell. That's the bread and butter of most Apps. Data structures are represented as a Model.

Lets build a Model. Our App will display a list of concerts. Models can of course be very complicated, this is simple one for illustrative purposes. What makes up a concert event?

A concert has a Name (Winter Blast), Location (Barclays Arena), Description (EDM concert with 12 bands), Date (1/1/2015), and an Image of that awesome flyer (flyer.png).

      // The Concert Model

      import Foundation

      class Concert {
          var name = String()
          var location = String()
          var description = String()
          var date = String()
          var image = String()

          init(name:String, location:String, description:String, date:String, image:String) {
     = name
              self.location = location
              self.description = description
     = date
              self.image = image


And lets break this out, line by line.

import Foundation

Direct from Apple docs:
This import makes all of the Foundation APIs—including NSDate, NSURL, NSMutableData, and all of their methods, properties, and categories—directly available in Swift.