LPDMvvmKit 源码学习笔记-01
2017-11-17 16:21
645 查看
转载 http://blog.csdn.net/mmoaay/article/details/51763100
最近有幸见识一个基于 ReactiveCocoa 实现的 iOS MVVM 框架。其中一些在我看来有些大费周章的做法着实让我吃惊,以至于觉得有必要对这个框架的源码进行一次深入的学习和分析。因为这个框架的实现有些复杂,所以我会以系列的方式来记录我的学习过程和分析结果,希望对大家有所帮助。
一个基于 ReactiveCocoa 实现的 iOS MVVM 框架。
熟悉 MVVM 架构思想并有一定的实践
熟练使用 ReactiveCocoa 框架
稻子_Aadan
https://github.com/foxsofter/lpd-mvvm-kit
Class-LPDMvvmKit LPDMvvmKit 库代码
Additions-对 Cocoa 框架功能的一些扩展,方便开发
Controls-自定义控件
LPDAlertView
LPDPopupView
LPDToastView
Mvvm-核心代码(关键)
Models-MVVM 框架的 M
Services-
ViewControllers-
ViewModels-MVVM 框架的 VM
Views-MVVM框架的 V
LPDMvvmKit-Demo
ViewControllers
ViewModels
Views
Services
Models
Pods CocoaPods-第三方库
AFNetworking
CocoaSecurity-加密解密库
DateTools-日期时间功能增强库
Kiwi-TDD开发框架
Masonry
MJRefresh
ReactiveCocoa-响应式编程框架(关键)
ReactiveViewModel-基于 ReactiveCocoa 实现的 ViewModel 库
SDiPhoneVersion-iPhone设备信息获取库
UICKeyChainStore
YYModel
通过对项目结构和文件的分析,得出初步的一个分析结果:
优势:
功能齐全,使用者通过本框架可以迅速完成常见 App 的基础部分搭建。
可改进:
有些模块的划分不是特别清晰。比如网络请求模块,应该可以独立出来做一个单独的库。
Additions 和 Controls 部分可以从 LPDMvvmKit 中独立出来,方便灵活配置。
Example 代码和库本身的代码的标识可以更明确一些。
分析库依赖最好的方式就是 podspec 文件,通过 LPDMvvmKit 的 podspec 我们可以看到:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
它的库依赖包括两个部分,一个是内部依赖,一个是第三方依赖。
内部依赖包括两个部分:
Additions
Controls
第三方依赖包括:
AFNetworking
ReactiveCocoa
ReactiveViewModel
UICKeyChainStore
YYModel
DateTools
Masonry
SDiPhoneVersion
理论上除了 ReactiveCocoa 和 ReactiveViewModel 两个必须依赖的库,其它部分可以进行解耦并独立出来。(PS:该部分所做的分析只是一个初步的分析,并不能做为源码剖析的结论)
前言
最近有幸见识一个基于 ReactiveCocoa 实现的 iOS MVVM 框架。其中一些在我看来有些大费周章的做法着实让我吃惊,以至于觉得有必要对这个框架的源码进行一次深入的学习和分析。因为这个框架的实现有些复杂,所以我会以系列的方式来记录我的学习过程和分析结果,希望对大家有所帮助。
关于 LPDMvvmKit
简介
一个基于 ReactiveCocoa 实现的 iOS MVVM 框架。
一些门槛
熟悉 MVVM 架构思想并有一定的实践熟练使用 ReactiveCocoa 框架
作者
稻子_Aadan
GayHub
https://github.com/foxsofter/lpd-mvvm-kit
项目分析
项目结构文件
Class-LPDMvvmKit LPDMvvmKit 库代码 Additions-对 Cocoa 框架功能的一些扩展,方便开发
Controls-自定义控件
LPDAlertView
LPDPopupView
LPDToastView
Mvvm-核心代码(关键)
Models-MVVM 框架的 M
Services-
ViewControllers-
ViewModels-MVVM 框架的 VM
Views-MVVM框架的 V
LPDMvvmKit-Demo
ViewControllers
ViewModels
Views
Services
Models
Pods CocoaPods-第三方库
AFNetworking
CocoaSecurity-加密解密库
DateTools-日期时间功能增强库
Kiwi-TDD开发框架
Masonry
MJRefresh
ReactiveCocoa-响应式编程框架(关键)
ReactiveViewModel-基于 ReactiveCocoa 实现的 ViewModel 库
SDiPhoneVersion-iPhone设备信息获取库
UICKeyChainStore
YYModel
通过对项目结构和文件的分析,得出初步的一个分析结果:
优势:
功能齐全,使用者通过本框架可以迅速完成常见 App 的基础部分搭建。
可改进:
有些模块的划分不是特别清晰。比如网络请求模块,应该可以独立出来做一个单独的库。
Additions 和 Controls 部分可以从 LPDMvvmKit 中独立出来,方便灵活配置。
Example 代码和库本身的代码的标识可以更明确一些。
库依赖
分析库依赖最好的方式就是 podspec 文件,通过 LPDMvvmKit 的 podspec 我们可以看到:# # Be sure to run `pod spec lint LPDMvvmKit.podspec' to ensure this is a # valid spec and to remove all comments including this before submitting the spec. # # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ # Pod::Spec.new do |s| s.name = "LPDMvvmKit" s.version = "0.4.2" s.summary = "mvvm" s.description = <<-DESC a framework of mvvm. * Think: Why did you write this? What is the focus? What does it do? * CocoaPods will be using 4000 this to generate tags, and improve search results. * Try to keep it short, snappy and to the point. * Finally, don't worry about the indent, CocoaPods strips it! DESC s.homepage = "https://github.com/foxsofter/lpd-mvvm-kit" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "foxsofter" => "foxsofter@gmail.com" } s.platform = :ios, "7.0" s.ios.deployment_target = "7.0" s.source = { :git => "https://github.com/foxsofter/lpd-mvvm-kit.git", :tag => "#{s.version}", :submodules => true } s.requires_arc = true s.subspec 'Additions' do |ss| ss.ios.deployment_target = '7.0' ss.source_files = 'Classes/Additions/*.{h,m}' ss.dependency 'AFNetworking' ss.dependency 'ReactiveCocoa', '2.5' ss.dependency 'DateTools' end s.subspec 'Controls' do |ss| ss.ios.deployment_target = '7.0' ss.dependency 'LPDMvvmKit/Additions' ss.dependency 'SDiPhoneVersion' ss.dependency 'Masonry' ss.source_files = 'Classes/Controls/LPDPopupView/*.{h,m}','Classes/Controls/LPDAlertView/*.{h,m}','Classes/Controls/LPDToastView/*.{h,m}' end s.subspec 'Mvvm' do |ss| ss.ios.deployment_target = '7.0' ss.dependency 'LPDMvvmKit/Additions' ss.dependency 'LPDMvvmKit/Controls' ss.dependency 'AFNetworking' ss.dependency 'ReactiveCocoa', '2.5' ss.dependency 'ReactiveViewModel' ss.dependency 'UICKeyChainStore' ss.dependency 'YYModel' ss.source_files = 'Classes/Mvvm/*.{h,m}','Classes/Mvvm/Services/*.{h,m}','Classes/Mvvm/Services/LKUserDefaults/*.{h,m}','Classes/Mvvm/Models/*.{h,m}','Classes/Mvvm/ViewControllers/*.{h,m}','Classes/Mvvm/ViewModels/*.{h,m}','Classes/Mvvm/Views/*.{h,m}' end end1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
它的库依赖包括两个部分,一个是内部依赖,一个是第三方依赖。
内部依赖包括两个部分:
Additions
Controls
第三方依赖包括:
AFNetworking
ReactiveCocoa
ReactiveViewModel
UICKeyChainStore
YYModel
DateTools
Masonry
SDiPhoneVersion
理论上除了 ReactiveCocoa 和 ReactiveViewModel 两个必须依赖的库,其它部分可以进行解耦并独立出来。(PS:该部分所做的分析只是一个初步的分析,并不能做为源码剖析的结论)
相关文章推荐
- LPDMvvmKit 源码学习笔记-01
- “计算机之子”的MVVM框架源码学习笔记
- 嵌入式操作系统学习笔记:01.书籍与OS源码选择
- Android源码学习笔记01
- Android Bluetooth源码学习笔记01
- C++ Standard Stl -- SGI STL源码学习笔记(01) auto_ptr
- cocos2d-x学习笔记01:VS开发环境搭建
- [lua源码学习笔记]词法语法分析
- 【锋利的jQuery】学习笔记01
- JBPM 4.4 学习笔记01----基本步骤
- nginx 源码学习笔记(二十二)—— event 模块(三) ——epoll模块
- python学习笔记-01
- AngularJs学习笔记[01]——数据绑定
- CAFFE源码学习笔记之batch_norm_layer
- MVVM架构~knockoutjs系列之从Knockout.Validation.js源码中学习它的用法
- Git学习笔记01--初始化设置
- cocos2dx内存管理机制学习笔记,源码分析
- 【学习笔记】Git学习记录01:前期准备_初步配置
- Servlet学习笔记_01_Servlet或javaee要了解的一些常识
- python数据结构学习笔记-2017-01-08-01-N皇后问题、迷宫问题和跳马问题的递归解决