Coder Social home page Coder Social logo

modelcreate's Introduction

#ModelCreate 一句代码生成数据模型

你只需要下载我的项目,然后使用的你URL运行,既可自动生成数据模型,

然后根据打印的路径,找到模型文件,拖进你的工程

对于和关键字冲突的字段,使用的时候,自己手动改一下就行

// 1.创建url
NSURL * url = [NSURL URLWithString:@"你请求的URL"];
// 2.创建session对象
NSURLSession * session = [NSURLSession sharedSession];
// 系统提供的全局的NSURLSession对象,单例
// 因为NSURLSession基于任务去完成相关的事件,所有的东西都放在任务内
// 3.创建task请求任务
// NSURLSessionTask就是NSURLSession任务的执行对象
NSURLSessionTask * task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

// 4.解析相关数据
NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

// 生成模型   Models文件夹下的 都是通过这句代码生成的
// 执行完会打印出生成文件的地址,前往这个文件夹既可找到,然后拖进你的项目中就可了
if (dict) {
    [CreateModel createModelWithJsonData:dict rootModelName:@"Model"];
}
// 默认的生成一个初始化方法
// Model *model = [[Model alloc] initWithDictionary:dict];
// 很多数据都有id这个字段,所以提供了一个后期维护的方法
// 以StudentModel为例 我们把.h中的id属性 替换成studentID
// 在点.m中的setValue:forUndefinedKey:方法中添加以下代码即可
// if([key isEqualToString:@"id"]) {
//     self.studentID = value;
//     return;
// }

}];

// 5.启动任务

// 原因:NSURLSessionTask,task任务是属于挂起的状态,如果不启动,不会走block中实现的内容

[task resume];

#效果图 运行后会自动打印出文件地址 image

前往文件夹 image

这些就是自动生成的模型文件了,直接拖进自己的工程使用就行 image

随便打开一个看一下, 对于字段于关键字冲突的,我们提供了后期维护的方法,按照图片所示,对.h和.m文件稍加修改即可 image

这是.m文件 image

modelcreate's People

Stargazers

 avatar xiaohengdd avatar JimmyCJJ avatar  avatar  avatar  avatar Metros avatar YaoJuan avatar  avatar shisanzhoufu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.