Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can somebody post a good example of MVC Pattern in Swift? [closed]

A simple project which has implemented the MVC pattern. So far,I have a brief understanding of how it is like but I want to see the practical implementation.

like image 584
Isha Balla Avatar asked Feb 07 '23 21:02

Isha Balla


1 Answers

This is a typical example of Model View Controller in swift:

class Article {
  var title: String
  var body: String
  var date: NSDate
  var thumbnail: NSURL
  var saved: Bool
}

class ArticleViewController: UIViewController {
  var bodyTextView: UITextView
  var titleLabel: UILabel
  var dateLabel: UILabel

  var article: Article {
    didSet {
      titleLabel.text = article.title
      bodyTextView.text = article.body

      let dateFormatter = NSDateFormatter()
      dateFormatter.dateStyle = NSDateFormatterStyle.ShortStyle
      dateLabel.text = dateFormatter.stringFromDate(article.date)
    }
  }
}
like image 142
Alessandro Ornano Avatar answered May 01 '23 18:05

Alessandro Ornano