YYModel
==============
[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/ibireme/YYModel/master/LICENSE)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![CocoaPods](http://img.shields.io/cocoapods/v/YYModel.svg?style=flat)](http://cocoapods.org/?q= YYModel)
[![CocoaPods](http://img.shields.io/cocoapods/p/YYModel.svg?style=flat)](http://cocoapods.org/?q= YYModel)
[![Build Status](https://travis-ci.org/ibireme/YYModel.svg?branch=master)](https://travis-ci.org/ibireme/YYModel)
[![codecov.io](https://codecov.io/github/ibireme/YYModel/coverage.svg?branch=master)](https://codecov.io/github/ibireme/YYModel?branch=master)
High performance model framework for iOS/OSX.<br/>
(It's a component of [YYKit](https://github.com/ibireme/YYKit))
Performance
==============
Time cost (process GithubUser 10000 times on iPhone 6):
![Benchmark result](https://raw.github.com/ibireme/YYModel/master/Benchmark/Result.png
)
See `Benchmark/ModelBenchmark.xcodeproj` for more benchmark case.
Features
==============
- **High performance**: The conversion performance is close to handwriting code.
- **Automatic type conversion**: The object types can be automatically converted.
- **Type Safe**: All data types will be verified to ensure type-safe during the conversion process.
- **Non-intrusive**: There is no need to make the model class inherit from other base class.
- **Lightwight**: This library contains only 5 files.
- **Docs and unit testing**: 100% docs coverage, 99.6% code coverage.
Usage
==============
###Simple model json convert
// JSON:
{
"uid":123456,
"name":"Harry",
"created":"1965-07-31T00:00:00+0000"
}
// Model:
@interface User : NSObject
@property UInt64 uid;
@property NSString *name;
@property NSDate *created;
@end
@implementation User
@end
// Convert json to model:
User *user = [User yy_modelWithJSON:json];
// Convert model to json:
NSDictionary *json = [user yy_modelToJSONObject];
If the type of an object in JSON/Dictionary cannot be matched to the property of the model, the following automatic conversion is performed. If the automatic conversion failed, the value will be ignored.
<table>
<thead>
<tr>
<th>JSON/Dictionary</th>
<th>Model</th>
</tr>
</thead>
<tbody>
<tr>
<td>NSString</td>
<td>NSNumber,NSURL,SEL,Class</td>
</tr>
<tr>
<td>NSNumber</td>
<td>NSString</td>
</tr>
<tr>
<td>NSString/NSNumber</td>
<td>C number (BOOL,int,float,NSUInteger,UInt64,...)<br/>
NaN and Inf will be ignored</td>
</tr>
<tr>
<td>NSString</td>
<td>NSDate parsed with these formats:<br/>
yyyy-MM-dd<br/>
yyyy-MM-dd HH:mm:ss<br/>
yyyy-MM-dd'T'HH:mm:ss<br/>
yyyy-MM-dd'T'HH:mm:ssZ<br/>
EEE MMM dd HH:mm:ss Z yyyy
</td>
</tr>
<tr>
<td>NSDate</td>
<td>NSString formatted with ISO8601:<br/>
"YYYY-MM-dd'T'HH:mm:ssZ"</td>
</tr>
<tr>
<td>NSValue</td>
<td>struct (CGRect,CGSize,...)</td>
</tr>
<tr>
<td>NSNull</td>
<td>nil,0</td>
</tr>
<tr>
<td>"no","false",...</td>
<td>@(NO),0</td>
</tr>
<tr>
<td>"yes","true",...</td>
<td>@(YES),1</td>
</tr>
</tbody>
</table>
###Match model property to different JSON key
// JSON:
{
"n":"Harry Pottery",
"p": 256,
"ext" : {
"desc" : "A book written by J.K.Rowing."
},
"ID" : 100010
}
// Model:
@interface Book : NSObject
@property NSString *name;
@property NSInteger page;
@property NSString *desc;
@property NSString *bookID;
@end
@implementation Book
+ (NSDictionary *)modelCustomPropertyMapper {
return @{@"name" : @"n",
@"page" : @"p",
@"desc" : @"ext.desc",
@"bookID" : @[@"id",@"ID",@"book_id"]};
}
@end
You can map a json key (key path) or an array of json key (key path) to one or multiple property name. If there's no mapper for a property, it will use the property's name as default.
###Nested model
// JSON
{
"author":{
"name":"J.K.Rowling",
"birthday":"1965-07-31T00:00:00+0000"
},
"name":"Harry Potter",
"pages":256
}
// Model: (no need to do anything)
@interface Author : NSObject
@property NSString *name;
@property NSDate *birthday;
@end
@implementation Author
@end
@interface Book : NSObject
@property NSString *name;
@property NSUInteger pages;
@property Author *author;
@end
@implementation Book
@end
### Container property
@class Shadow, Border, Attachment;
@interface Attributes
@property NSString *name;
@property NSArray *shadows; //Array<Shadow>
@property NSSet *borders; //Set<Border>
@property NSMutableDictionary *attachments; //Dict<NSString,Attachment>
@end
@implementation Attributes
+ (NSDictionary *)modelContainerPropertyGenericClass {
// value should be Class or Class name.
return @{@"shadows" : [Shadow class],
@"borders" : Border.class,
@"attachments" : @"Attachment" };
}
@end
### Whitelist and blacklist
@interface User
@property NSString *name;
@property NSUInteger age;
@end
@implementation Attributes
+ (NSArray *)modelPropertyBlacklist {
return @[@"test1", @"test2"];
}
+ (NSArray *)modelPropertyWhitelist {
return @[@"name"];
}
@end
###Data validate and custom transform
// JSON:
{
"name":"Harry",
"timestamp" : 1445534567
}
// Model:
@interface User
@property NSString *name;
@property NSDate *createdAt;
@end
@implementation User
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
NSNumber *timestamp = dic[@"timestamp"];
if (![timestamp isKindOfClass:[NSNumber class]]) return NO;
_createdAt = [NSDate dateWithTimeIntervalSince1970:timestamp.floatValue];
return YES;
}
- (BOOL)modelCustomTransformToDictionary:(NSMutableDictionary *)dic {
if (!_createdAt) return NO;
dic[@"timestamp"] = @(n.timeIntervalSince1970);
return YES;
}
@end
###Coding/Copying/hash/equal/description
@interface YYShadow :NSObject <NSCoding, NSCopying>
@property (nonatomic, copy) NSString *name;
@property (nonatomic, assign) CGSize size;
@end
@implementation YYShadow
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; }
- (id)initWithCoder:(NSCoder *)aDecoder { self = [super init]; return [self yy_modelInitWithCoder:aDecoder]; }
- (id)copyWithZone:(NSZone *)zone { return [self yy_modelCopy]; }
- (NSUInteger)hash { return [self yy_modelHash]; }
- (BOOL)isEqual:(id)object { return [self yy_modelIsEqual:object]; }
- (NSString *)description { return [self yy_modelDescription]; }
@end
Installation
==============
### CocoaPods
1. Add `pod 'YYModel'` to your Podfile.
2. Run `pod install` or `pod update`.
3. Import \<YYModel/YYModel.h\>.
### Carthage
1. Add `github "ibireme/YYModel"` to your Cartfile.
2. Run `carthage update --platform ios` and add the framework to your project.
3. Import \<YYModel/YYModel.h\>.
### Manually
1. Download all the files in the YYModel subdirectory.
2. Add the source files to your Xcode project.
3. Import `YYModel.h`.
Documentation
==============
Full API documentation is available on [CocoaDocs](http://cocoadocs.org/docsets/YYModel/).<br/>
You can also install documentation locally using [appledoc](https://github.com/tomaz/appledoc).
Requirements
==============
This library requires `iOS 6.0+` and `Xcode 7.0+`.
License
==============
YYModel is provided under the MIT license. See LICENSE file for details.
<br/><br/>
---
中文介绍
==============
高性能 iOS/OSX 模型转换框架。<br/>
(该项目是 [YYKit](https://github.com/ibireme/YYKit) 组件之一)
性能
==============
处理 GithubUser 数据 10000 次耗时统计 (iPhone 6):
![Benchma
没有合适的资源?快使用搜索试试~ 我知道了~
sketch-IB:从sketch-html快速轻松地生成界面生成器
共94个文件
h:21个
png:16个
m:16个
需积分: 19 1 下载量 17 浏览量
2021-02-06
02:38:42
上传
评论
收藏 3.91MB ZIP 举报
温馨提示
SketchHtmlToiOSIB 新增功能记录 1,增加子控件嵌套功能:查看支持一级,二级嵌套 2,增加按钮识别功能:支持一级按钮,二级按钮合成 3,加载图片功能 4,支持输入框控件 5,修复一些特殊蒙板侧壁问题 6,添加识别字体类型(PingFangHK-Regular,PingFangSC-Light,PingFangHK-Medium,STHeitiSC-Light) 如何使用 1.把美工给的Sketch的网页存到本地,当然有时美工给的就是压缩包,就省去了下载这一步 2.运行本程序 3.把1中存的网页的html拖入程序面板 4.生成temp.xcodeproj至桌面 转换成你的故事板
资源详情
资源评论
资源推荐
收起资源包目录
sketch-IB-master.zip (94个子文件)
sketch-IB-master
show1.png 431KB
act.gif 2.59MB
SketchHtmlToiOSIB
SketchHtmlToiOSIB.xcodeproj
project.xcworkspace
contents.xcworkspacedata 200B
xcshareddata
IDEWorkspaceChecks.plist 238B
project.pbxproj 24KB
SketchHtmlToiOSIB
Assets.xcassets
AppIcon.appiconset
16.png 557B
32.png 1KB
32-1.png 1KB
Contents.json 1KB
128.png 8KB
512.png 74KB
256.png 24KB
64.png 3KB
编辑.imageset
编辑@2x.png 499B
Contents.json 342B
编辑@3x.png 765B
Contents.json 62B
main.m 238B
NSString+Add.h 402B
model
NBSKObject.m 1KB
NBSKObject.h 5KB
SXBaseModel.m 2KB
SXBaseModel.h 485B
AppDelegate.h 225B
AppDelegate.m 482B
view
XMFileItem.h 631B
XMFileItem.m 869B
XMDragView.m 2KB
XMDragView.h 478B
Base.lproj
Main.storyboard 60KB
NSXMLElement+Add.h 957B
SketchHtmlToiOSIB.entitlements 181B
NSString+Add.m 1KB
ViewController.h 418B
Info.plist 1KB
ViewController.m 2KB
xml
imageView.xml 372B
button.xml 898B
vc.xml 959B
project.pbxproj 2KB
view.xml 471B
sb.xml 841B
textField.xml 743B
label.xml 752B
NSXMLElement+Add.m 14KB
ViewController+Add.h 461B
ViewController+Add.m 43KB
Podfile 254B
Podfile.lock 429B
Pods
Target Support Files
YYModel
YYModel-prefix.pch 195B
YYModel-dummy.m 118B
YYModel.xcconfig 646B
Pods-SketchHtmlToiOSIB
Pods-SketchHtmlToiOSIB-acknowledgements.markdown 2KB
Pods-SketchHtmlToiOSIB.release.xcconfig 816B
Pods-SketchHtmlToiOSIB-resources.sh 6KB
Pods-SketchHtmlToiOSIB-frameworks.sh 7KB
Pods-SketchHtmlToiOSIB-dummy.m 148B
Pods-SketchHtmlToiOSIB-acknowledgements.plist 3KB
Pods-SketchHtmlToiOSIB.debug.xcconfig 816B
MBProgressHUD-OSX
MBProgressHUD-OSX-dummy.m 138B
MBProgressHUD-OSX-prefix.pch 195B
MBProgressHUD-OSX.xcconfig 658B
YYModel
YYModel
YYModel.h 595B
NSObject+YYModel.h 13KB
YYClassInfo.m 13KB
NSObject+YYModel.m 83KB
YYClassInfo.h 8KB
LICENSE 1KB
README.md 16KB
Manifest.lock 429B
Headers
Public
YYModel
YYModel.h 34B
NSObject+YYModel.h 43B
YYClassInfo.h 38B
MBProgressHUD-OSX
MBProgressHUD.h 50B
Private
YYModel
YYModel.h 34B
NSObject+YYModel.h 43B
YYClassInfo.h 38B
MBProgressHUD-OSX
MBProgressHUD.h 50B
Pods.xcodeproj
project.pbxproj 31KB
MBProgressHUD-OSX
LICENSE 1KB
README.md 58B
Classes
MBProgressHUD.h 25KB
MBProgressHUD.m 71KB
SketchHtmlToiOSIB.xcworkspace
contents.xcworkspacedata 235B
xcshareddata
IDEWorkspaceChecks.plist 238B
show2.png 240KB
LICENSE 1KB
SketchPage.png 166KB
contain2.png 96KB
contain1.png 73KB
.gitignore 1KB
README.md 3KB
fastUse.png 23KB
SbPage.png 276KB
共 94 条
- 1
皮卡学长
- 粉丝: 76
- 资源: 4622
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- labview简易计算器,类似于windows自带的计算器 浙理工同学可以无脑下载
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本121.0.6150.0)
- 基于Python+opencv的多人脸检测,口罩佩戴检测,单目标跟踪
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本121.0.6148.0)
- 基于C++版本的sort算法,可无缝添加在检测器后进行实时多目标跟踪
- 基于物联网的户外环境监测系统设计.docx
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本121.0.6146.0)
- 1_6、CC2530 查询方式使用定时器.pdf
- 测绘程序设计-五点光滑法曲线拟合
- 基于 C++实现的多特征(色调+边缘+纹理)融合的目标跟踪
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0