Skip to content

Commit 7d605b1

Browse files
committed
Update README
1 parent ea7b360 commit 7d605b1

4 files changed

Lines changed: 105 additions & 7 deletions

File tree

README.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,98 @@
1-
# YBModelFile
1+
# YBModelFile (Latest version : 1.0)
2+
3+
iOS 效率工具:自动生成 Model 文件(数据模型) / iOS efficiency tool : create data model files automatically
4+
5+
技术原理博客:TODO
6+
7+
8+
## 特性
9+
10+
- 一句代码自动生成数据模型文件
11+
- 支持 YYModel / MJExtension 的自动映射
12+
- 自动过滤转换类名和属性名
13+
- 自动实现 NSCopying / NSCoding 协议方法
14+
- 支持文件创建策略:一个类一组文件或并为一组文件
15+
- 支持属性类型的过滤策略
16+
- 算法处理模块粒度小且面向协议,可自由定制局部算法
17+
18+
19+
20+
## 安装
21+
22+
### CocoaPods
23+
24+
1. 在 Podfile 中添加 `pod 'YBModelFile'`
25+
2. 执行 `pod install``pod update`
26+
3. 导入 `<YBModelFile/YBModelFile.h>`
27+
28+
### 手动导入
29+
30+
1. 下载 YBModelFile 文件夹所有内容并且拖入你的工程中。
31+
2. 导入 `YBModelFile.h`
32+
33+
34+
## 用法
35+
36+
可下载 DEMO 查看示例。
37+
38+
### 基本使用
39+
40+
```objc
41+
NSString *name = ...; //主 Model 文件名字
42+
id data = ...; //json数据
43+
[YBModelFile createFileWithName:name data:data];
44+
```
45+
一句代码调用过后,工具会自动在桌面上创建一个 YBModelFile-Workspace 文件夹,之后所有自动创建的 Model 文件会存储在该文件夹下,只需要将它们拖入工程就能直接使用。
46+
47+
当然,可以使用`-createFileWithName:data:path:`方法中的`path`指定工作空间的存储路径。
48+
49+
### 字典转模型框架设置
50+
51+
由于工具会自动进行属性和数组元素的映射,你需要指定工程使用的字典转模型框架,目前支持 YYModel 和 MJExtension。
52+
```objc
53+
[YBMFConfig shareConfig].framework = YBMFFrameworkYY;
54+
```
55+
56+
### NSCoding 和 NSCopying 协议
57+
58+
NSCoding 和 NSCopying 协议是否实现可以指定:
59+
```objc
60+
[YBMFConfig shareConfig].needCoding = NO;
61+
[YBMFConfig shareConfig].needCopying = NO;
62+
```
63+
64+
### 属性和方法之间是否空行
65+
66+
工具提供简单的定制:
67+
```objc
68+
[YBMFConfig shareConfig].fileHHandler.ybmf_skipLine = YES;
69+
[YBMFConfig shareConfig].fileMHandler.ybmf_skipLine = YES;
70+
```
71+
72+
### 类名公用后缀
73+
74+
默认情况下,类名公用后缀为`Model`,可以自行定制:
75+
```objc
76+
[YBMFConfig shareConfig].fileSuffix = @"File";
77+
```
78+
79+
### 属性忽略类型
80+
81+
在构建 Model 时,往往需要过滤掉一些类型,比如需要使用`NSString`提到`NSNumber`,过滤掉字典中的可变类型。这些都可以通过一个多选枚举来配置,过滤的类型工具会使用更宽泛的类型来处理。
82+
```objc
83+
[YBMFConfig shareConfig].ignoreType = YBMFIgnoreTypeAllDigital | YBMFIgnoreTypeMutable;
84+
```
85+
86+
### 文件划分策略
87+
88+
目前支持两种策略,一种是所有类都放到一组文件 (.h/.m),一种是一个类对应一组文件:
89+
```objc
90+
[YBMFConfig shareConfig].filePartitionMode = YBMFFilePartitionModeApart;
91+
```
92+
93+
94+
# TODO
95+
96+
通常情况下,该工具使用比较顺手,但是会有一些问题:
97+
- json 嵌套过深,类名过长:工具目前是使用 json 的 key 来拓展拼接类名的,所以 json 套得越深类名越长。后面考虑两种处理方法,一是限制类名长度,二是使用与 key 无关的类名拓展策略,不过显而易见每种方式都有缺陷。
98+
- 文件拆分粒度控制:目前工具支持要么合并为一组文件,要么完全分开。考虑在复杂场景下,可能需要按需拆分,比如 100 model 类需要划分为 10 组 .h/.m 文件。目前能想到的是三种方式:一是对关系树按照层级划分文件,在一层的类划分到一个文件,这种处理方式的缺点是一个文件的所有类是兄弟节点没有什么逻辑关联,不便于管理;二是通过设置一个最大层级来控制,比如设置的层级是 3,那么第 3 层之后的子节点类都合并到第 3 层的类文件中;三是在深搜过程中记录文件中的类数量,一个文件达到数量限制就创建新的文件来写入类。

YBModelFile.podspec

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ Pod::Spec.new do |s|
55

66
s.name = "YBModelFile"
77
s.version = "1.0"
8-
s.summary = "iOS Model 自动生成工具 (数据模型)"
8+
s.summary = "iOS 效率工具:自动生成 Model 文件(数据模型) / iOS efficiency tool : create data model files automatically"
99
s.description = <<-DESC
10-
iOS Model 自动生成工具 (数据模型),只需传入一个 json 数据就能自动生成所需文件,拖入工程就能使用。
10+
iOS 效率工具:自动生成 Model 文件(数据模型) / iOS efficiency tool : create data model files automatically
11+
只需传入一个 json 数据就能自动生成所需文件,拖入工程就能使用。
1112
DESC
1213

1314
s.homepage = "https://github.com/indulgeIn"
@@ -18,9 +19,9 @@ Pod::Spec.new do |s|
1819

1920
s.platform = :ios, "8.0"
2021

21-
s.source = { :git => "https://github.com/indulgeIn/YBTaskScheduler.git", :tag => "#{s.version}" }
22+
s.source = { :git => "https://github.com/indulgeIn/YBModelFile.git", :tag => "#{s.version}" }
2223

23-
s.source_files = "YBModelFile/**/*.{h,m,mm}"
24+
s.source_files = "YBModelFile/**/*.{h,m}"
2425

2526
s.requires_arc = true
2627

YBModelFile/Handler/YBMFNameHandler.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ - (NSString *)ybmf_propertyNameWithKey:(id)key node:(nonnull YBMFNode *)node {
192192
NSSet *illegalVars = YBClassVarsExceptPrefix([YBMFConfig shareConfig].baseClass);
193193
while ([node.children.allKeys containsObject:tmp] || [illegalVars containsObject:tmp]) {
194194
tmp = keyStr.copy;
195-
tmp = [tmp stringByAppendingString:[NSString stringWithFormat:@"%lu", ++suf]];
195+
tmp = [tmp stringByAppendingString:[NSString stringWithFormat:@"%lu", (unsigned long)++suf]];
196196
}
197197
return tmp;
198198
}

YBModelFile/YBModelFile.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ - (NSString *)creatDirectoryWithPath:(NSString *)path directoryName:(NSString *)
166166
if (exist && cover) return directoryPath;
167167
NSUInteger suffix = 0;
168168
while (exist) {
169-
directoryPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%lu", directoryName, ++suffix]];
169+
directoryPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%lu", directoryName, (unsigned long)++suffix]];
170170
exist = [[NSFileManager defaultManager] fileExistsAtPath:directoryPath];
171171
}
172172
NSError *error;

0 commit comments

Comments
 (0)