有人可以在Swift中发布MVC模式的好例子吗? [英] Can somebody post a good example of MVC Pattern in Swift?

查看:75
本文介绍了有人可以在Swift中发布MVC模式的好例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个实现了MVC模式的简单项目.到目前为止,我对它的状态有一个简短的了解,但我想看看实际的实现.

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.

推荐答案

这是Swift中Model View Controller的典型示例:

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

这篇关于有人可以在Swift中发布MVC模式的好例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆