{"id":18725096,"url":"https://github.com/indulgein/ybmodelfile","last_synced_at":"2025-08-20T18:34:17.699Z","repository":{"id":56928852,"uuid":"176242725","full_name":"indulgeIn/YBModelFile","owner":"indulgeIn","description":"根据 JSON 自动生成 Model 文件（数据模型）","archived":false,"fork":false,"pushed_at":"2019-12-23T14:30:22.000Z","size":689,"stargazers_count":225,"open_issues_count":1,"forks_count":28,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-03-15T03:02:55.594Z","etag":null,"topics":["auto-complete","data-model","efficiency"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/indulgeIn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-18T09:02:39.000Z","updated_at":"2024-03-11T02:12:25.000Z","dependencies_parsed_at":"2022-08-21T06:20:20.193Z","dependency_job_id":null,"html_url":"https://github.com/indulgeIn/YBModelFile","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indulgeIn%2FYBModelFile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indulgeIn%2FYBModelFile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indulgeIn%2FYBModelFile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/indulgeIn%2FYBModelFile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/indulgeIn","download_url":"https://codeload.github.com/indulgeIn/YBModelFile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230445927,"owners_count":18227060,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto-complete","data-model","efficiency"],"created_at":"2024-11-07T14:09:03.116Z","updated_at":"2024-12-19T14:08:23.797Z","avatar_url":"https://github.com/indulgeIn.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# YBModelFile \n\n[![Cocoapods](https://img.shields.io/cocoapods/v/YBModelFile.svg)](https://cocoapods.org/pods/YBModelFile)\u0026nbsp;\n[![Cocoapods](https://img.shields.io/cocoapods/p/YBModelFile.svg)](https://github.com/indulgeIn/YBModelFile)\u0026nbsp;\n[![License](https://img.shields.io/github/license/indulgeIn/YBModelFile.svg)](https://github.com/indulgeIn/YBModelFile)\u0026nbsp;\n\n\n根据 JSON 自动生成 Model 文件（数据模型）\n\n技术原理博客：[iOS 效率工具：自动生成 Model 文件](https://www.jianshu.com/p/f30cf05054c6)\n\n注意：仅在模拟器下运行有效\n\n## 特性\n\n- 一句代码自动生成数据模型文件\n- 支持 YYModel / MJExtension 的自动映射\n- 自动过滤转换类名和属性名\n- 自动实现 NSCopying / NSCoding 协议方法\n- 支持文件创建策略：一个类一组文件或并为一组文件\n- 支持属性类型的过滤策略\n- 算法处理模块粒度小且面向协议，可自由定制局部算法\n\n\n\n## 安装\n\n### CocoaPods\n\n1. 在 Podfile 中添加 `pod 'YBModelFile', :configurations =\u003e ['Debug']`。\n2. 执行 `pod install` 或 `pod update`。\n3. 导入 `\u003cYBModelFile/YBModelFile.h\u003e`。\n\n若搜索不到库，可使用 rm ~/Library/Caches/CocoaPods/search_index.json 移除本地索引然后再执行安装，或者更新一下 CocoaPods 版本。\n\n### 手动导入\n\n1. 下载 YBModelFile 文件夹所有内容并且拖入你的工程中。\n2. 导入 `YBModelFile.h`。\n\n\n## 用法\n\n可下载 DEMO 查看示例。\n\n### 基本使用\n\n```objc\nNSString *name = ...;   //主 Model 文件名字\nid data = ...;          //json数据\n[YBModelFile createFileWithName:name data:data];\n```\n一句代码调用过后，工具会自动在桌面上创建一个 YBModelFile-Workspace 文件夹，之后所有自动创建的 Model 文件会存储在该文件夹下，只需要将它们拖入工程就能直接使用。\n\n当然，可以使用`-createFileWithName:data:path:`方法中的`path`指定工作空间的存储路径。\n\n### 字典转模型框架设置\n\n由于工具会自动进行属性和数组元素的映射，你需要指定工程使用的字典转模型框架，目前支持 YYModel 和 MJExtension。\n```objc\n[YBMFConfig shareConfig].framework = YBMFFrameworkYY;\n```\n\n### NSCoding 和 NSCopying 协议\n\nNSCoding 和 NSCopying 协议是否实现可以指定：\n```objc\n[YBMFConfig shareConfig].needCoding = NO;\n[YBMFConfig shareConfig].needCopying = NO;\n```\n\n### 属性和方法之间是否空行\n\n工具提供简单的定制：\n```objc\n[YBMFConfig shareConfig].fileHHandler.ybmf_skipLine = YES;\n[YBMFConfig shareConfig].fileMHandler.ybmf_skipLine = YES;\n```\n\n### 类名公用后缀\n\n默认情况下，类名公用后缀为`Model`，可以自行定制：\n```objc\n[YBMFConfig shareConfig].fileSuffix = @\"File\";\n```\n\n### 属性忽略类型\n\n在构建 Model 时，往往需要过滤掉一些类型，比如需要使用`NSString`提到`NSNumber`，过滤掉字典中的可变类型。这些都可以通过一个多选枚举来配置，过滤的类型工具会使用更宽泛的类型来处理。\n```objc\n[YBMFConfig shareConfig].ignoreType = YBMFIgnoreTypeAllDigital | YBMFIgnoreTypeMutable;\n```\n\n### 文件划分策略\n\n目前支持两种策略，一种是所有类都放到一组文件 (.h/.m)，一种是一个类对应一组文件：\n```objc\n[YBMFConfig shareConfig].filePartitionMode = YBMFFilePartitionModeApart;\n```\n\n### 处理算法自定义\n\n对于工具中的算法，都是通过一些类来处理，默认有实现，如果需要自定义，只需要实现对应的协议并且赋值给配置单例：\n```objc\n/** 名字处理器 */\n@property (nonatomic, strong) id\u003cYBMFNameHandler\u003e nameHander;\n/** 文件头部注解处理器 */\n@property (nonatomic, strong) id\u003cYBMFFileNoteHandler\u003e fileNoteHander;\n/** .h文件代码处理器 */\n@property (nonatomic, strong) id\u003cYBMFFileHHandler\u003e fileHHandler;\n/** .m文件代码处理器 */\n@property (nonatomic, strong) id\u003cYBMFFileMHandler\u003e fileMHandler;\n/** 节点作为父节点的属性时 Code 格式处理器 */\n@property (nonatomic, strong) id\u003cYBMFCodeForParentHandler\u003e codeForParentHandler;\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findulgein%2Fybmodelfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Findulgein%2Fybmodelfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Findulgein%2Fybmodelfile/lists"}