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