LPDMvvmKit 源码学习笔记-01
2016-10-07 21:49
288 查看
前言
最近有幸见识一个基于 ReactiveCocoa 实现的 iOS MVVM 框架。其中一些在我看来有些大费周章的做法着实让我吃惊,以至于觉得有必要对这个框架的源码进行一次深入的学习和分析。因为这个框架的实现有些复杂,所以我会以系列的方式来记录我的学习过程和分析结果,希望对大家有所帮助。关于 LPDMvvmKit
简介
一个基于 ReactiveCocoa 实现的 iOS MVVM 框架。一些门槛
熟悉 MVVM 架构思想并有一定的实践熟练使用 ReactiveCocoa 框架
作者
稻子_AadanGayHub
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 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 end
它的库依赖包括两个部分,一个是内部依赖,一个是第三方依赖。
内部依赖包括两个部分:
Additions
Controls
第三方依赖包括:
AFNetworking
ReactiveCocoa
ReactiveViewModel
UICKeyChainStore
YYModel
DateTools
Masonry
SDiPhoneVersion
理论上除了 ReactiveCocoa 和 ReactiveViewModel 两个必须依赖的库,其它部分可以进行解耦并独立出来。(PS:该部分所做的分析只是一个初步的分析,并不能做为源码剖析的结论)
后续
后面会针对 LPDBMvvmKit 的核心部分按模块进行分析,敬请期待!相关文章推荐
- LPDMvvmKit 源码学习笔记-01
- Android Bluetooth源码学习笔记01
- “计算机之子”的MVVM框架源码学习笔记
- Android源码学习笔记01
- C++ Standard Stl -- SGI STL源码学习笔记(01) auto_ptr
- 嵌入式操作系统学习笔记:01.书籍与OS源码选择
- C#学习笔记和年轻真好 08/01/19
- Java 学习笔记-01
- [LUA学习笔记01]用VS2003(C++)编译Hello Lua程序
- javascript 学习笔记01-一道题让你了解for循环
- 老友记台词学习笔记 SE01EP04(二)
- C#学习笔记 08/01/18
- FreeBSD学习笔记01-基本命令
- 2410 TFTP源码 学习笔记414757749
- ucos学习笔记01---OSUnMapTbl的理解
- TGE学习笔记01 - 初见Torque
- C# 学习笔记 (Assembly)-01
- php学习笔记-01
- (源码实例)通过层DIV实现,当鼠标放在链接上面,显示图片及文字 - 流星絮语 JAVA学习笔记 - CSDNBlog
- Servlet 与 Jsp核心编程 卷一 学习笔记 01