github:https://github.com/CharlinFeng/Reflect

直接拖拽Reflect文件夹到您的项目中即可,无任何第三方依赖!
文件夹结构说明:
.Coding 归档相关
.Reflect 反射核心包
.Dict2Model 字典转模型
.Model2Dict 模型转字典

这里使用plist作为数据源, plist存储的是一个数组, 数组中存储的是字典

plist的结构如下:

将plist数组中的每一个字典转换为模型, 代码如下:

RPTableViewController.swift:

import UIKit

class RPTableViewController: UITableViewController {

    var datas:[RPCityGroupModel] = Array()

    override func viewDidLoad()
{
super.viewDidLoad() let path = NSBundle.mainBundle().pathForResource("cityGroups", ofType: ".plist")
let arr = NSArray(contentsOfFile: path!)
for dict in arr! {
self.datas.append(RPCityGroupModel.parse(dict: dict as! NSDictionary))
} self.navigationItem.leftBarButtonItem = editButtonItem()
} // MARK: - Table view data source override func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return self.datas.count
} override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.datas[section].cities.count
} override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) cell.textLabel!.text = self.datas[indexPath.section].cities[indexPath.row] return cell
} override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
return self.datas[section].title
} override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]?
{
var indexTitles: [String] = Array()
for model in self.datas {
indexTitles.append(model.title)
}
return indexTitles
} override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
if editingStyle == .Delete {
self.datas[indexPath.section].cities.removeAtIndex(indexPath.row)
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
}

RPCityGroupModel.swift:

这里要注意的是, 模型是继承于Reflect这个类的

import UIKit

class RPCityGroupModel: Reflect
{
var cities: [String] = []
var title: String = ""
}

gif:

Swift缩水版MJExtension - Reflect的基本使用的更多相关文章

  1. swift kilo版代码更新

    今天重新搭建swift服务器,git下代码后一时好奇,进入kilo/stable branch后,与四个月前下载的swift/kilo版本做了个比较.使用diff命令完成.发现代码还是略有区别. di ...

  2. vue 缩水版 双向绑定

    function Observer(obj, key, value){ var dep = new Dep(); if (Object.prototype.toString.call(value) = ...

  3. 来实现一个缩水版Vuex

    对 Vuex 源码进行浓缩,DIY 一个小型 Vuex 功能如下 通过 $store.commit 改变 $store.state 实现 strict model 源码约70行左右比较好理解,下面讲解 ...

  4. 算法与数据结构(八) AOV网的关键路径(Swift版)

    上篇博客我们介绍了AOV网的拓扑序列,请参考<数据结构(七) AOV网的拓扑排序(Swift面向对象版)>.拓扑序列中包括项目的每个结点,沿着拓扑序列将项目进行下去是肯定可以将项目完成的, ...

  5. 算法与数据结构(七) AOV网的拓扑排序(Swift版)

    今天博客的内容依然与图有关,今天博客的主题是关于拓扑排序的.拓扑排序是基于AOV网的,关于AOV网的概念,我想引用下方这句话来介绍: AOV网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...

  6. 算法与数据结构(二) 栈与队列的线性和链式表示(Swift版)

    数据结构中的栈与队列还是经常使用的,栈与队列其实就是线性表的一种应用.因为线性队列分为顺序存储和链式存储,所以栈可以分为链栈和顺序栈,队列也可分为顺序队列和链队列.本篇博客其实就是<数据结构之线 ...

  7. swift开源项目精选

    Swift 开源项目精选-v1.0 2016-03-07 22:11 542人阅读 评论(0) 收藏 举报  分类: iOS(55)   Swift(4)    目录(?)[+]   转自 http: ...

  8. 43个优秀的Swift开源项目

    作为一门集百家之长的新语言,Swift拥有着苹果先天的生态优势,而其在GitHub上各种优秀的开源项目也层出不穷.本文作者@SwiftLanguage从2014年6月苹果发布Swift语言以来,便通过 ...

  9. Swift - 开源框架总结

    苹果官方Swift文档<The Swift Programming Language> 苹果开发者Swift文档及介绍 网友整理的Swift中文文档< Apple Swift编程语言 ...

随机推荐

  1. Mysql中的DQL查询语句

    ----------------1.查询所有列 --查询 学生 表所有记录(行) select *from 学生 --带条件的查询 select *from 学生 where 年龄>19 --- ...

  2. PHP自定义弹出消息类,用于弹出提示信息并返回

    一个用PHP自写的弹出消息类,用于在程序出错时弹出提示,,弹出警告框,或在程序运行到某阶段的快捷提示,需用时只需传入参数即可,函数并不复杂,但觉得挺实用.具体代码: function Alert($a ...

  3. String对象

    <script type="text/javascript"> /* var str1 = new String("hello"); var str ...

  4. Linux下如何发布Qt程序

    在X11平台下qt程序,首先准备好程序中需要使用的资源,库和插件...    比如你的可运行程序取名叫作panel,那把你的panel,那些libQt*.so.4和libQt*.so.4.6.0(链接 ...

  5. fiddler Composer 构建请求

    Fiddler的作者把HTTP Request发射器取名叫Composer(中文意思是:乐曲的创造者),以前叫做Request Builder Fiddler Composer的功能就是用来创建HTT ...

  6. iOS项目更新之升级Xcode7 & iOS9

    金田 前言      Apple 的WWDC所发布内容在给大家带来惊喜之际,给各位iOS开发的同仁却也带来了不同程度的麻烦.首先不讲新功能,就单指原来老版本的项目升级.代码升级,就是一堆问题,而且是不 ...

  7. HDOJ 1061 Rightmost Digit(循环问题)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  8. cf509E Pretty Song

    E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. Android样式的编写格式

    <?xml version="1.0" encoding="utf-8"?> <resources> <style name=&q ...

  10. [LeetCode] Maximum Gap 解题思路

    Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...