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

℡╲_俬逩灬. 提交于 2020-01-02 06:34:07

问题


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.


回答1:


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)
    }
  }
}


来源:https://stackoverflow.com/questions/37584595/can-somebody-post-a-good-example-of-mvc-pattern-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!