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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
软件开发设计:PHP、QT、应用软件开发、系统软件开发、移动应用开发、网站开发C++、Java、python、web、C#等语言的项目开发与学习资料 硬件与设备:单片机、EDA、proteus、RTOS、包括计算机硬件、服务器、网络设备、存储设备、移动设备等 操作系统:LInux、IOS、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信是一个非常广泛的领域,它涉及到计算机科学、电子工程、数学等多个学科的知识。 云计算与大数据:数据集、包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。
资源推荐
资源详情
资源评论
收起资源包目录
南大金陵校园足球系统(iOS+服务器).zip (1332个子文件)
1.3.4.0300a2c 14B
4.5.0.0d87c74 14B
4.6.1.fa6cc66.3DMap752 23B
2.3.0.47cf7aa 14B
2.3.1.8183fd9 14B
AMapFoundationKit 3.68MB
AMapLocationKit 3.78MB
AMapNaviKit 20.22MB
AMapSearchKit 4.2MB
SysUserController.class 5KB
SysUserController.class 5KB
PlayerBasedController.class 4KB
PlayerBasedController.class 4KB
PlayerSpec.class 2KB
PlayerSpec.class 2KB
MD5Util.class 2KB
MD5Util.class 2KB
Player.class 2KB
Player.class 2KB
ISysUserServiceImpl.class 2KB
ISysUserServiceImpl.class 2KB
IPlayerBasedServiceImpl.class 1KB
IPlayerBasedServiceImpl.class 1KB
SysUser.class 1KB
SysUser.class 1KB
StringUtils.class 1KB
JsonUtils.class 1KB
StringUtils.class 1KB
JsonUtils.class 1KB
PlayerLoginDto.class 913B
PlayerLoginDto.class 913B
EncodingUtils.class 705B
EncodingUtils.class 705B
ISysUserDao.class 509B
ISysUserDao.class 509B
Constants.class 477B
Constants.class 477B
ISysUserService.class 455B
ISysUserService.class 455B
IPlayerDao.class 438B
IPlayerDao.class 438B
IPlayerBasedService.class 376B
IPlayerBasedService.class 376B
TransformationMatrix.cpp 37KB
icons_2_7_1445580283.data 224KB
icons_1_7_1444880368.data 163KB
icons_3_7_1444880372.data 146KB
icons_50_7_1444880375.data 110KB
3d_sky_1.data 44KB
roadarrow.data 43KB
3d_sky_2.data 41KB
dash.data 21KB
tnl_n.data 21KB
tnl_l.data 21KB
dash_cd.data 21KB
tyl_l.data 21KB
dash_tq.data 21KB
tbl_n.data 21KB
tnl.data 21KB
tgl.data 21KB
tgl_n.data 21KB
tbl_l.data 21KB
trl_n.data 21KB
trl_l.data 21KB
tbl.data 21KB
tyl.data 21KB
tyl_n.data 21KB
tgl_l.data 21KB
trl.data 21KB
lineround.data 11KB
style_1_7_1445219169.data 10KB
style_6_7_1445325996.data 9KB
style_3_7_1445827513.data 8KB
style_4_7_1445391691.data 7KB
style_5_7_1445391719.data 7KB
style_50_7_1445670996.data 1KB
bktile_1.data 151B
bktile_2.data 145B
.gitignore 3KB
FMDatabase.h 45KB
MAMapView.h 30KB
AFURLSessionManager.h 29KB
AMapSearchObj.h 24KB
AMapCommonObj.h 24KB
AFURLRequestSerialization.h 22KB
AFHTTPSessionManager.h 19KB
AMapNaviCommonObj.h 17KB
MAGeometry.h 14KB
NSObject+YYModel.h 13KB
POPVector.h 13KB
MAOverlayRenderer.h 12KB
FMResultSet.h 12KB
AFURLResponseSerialization.h 12KB
POPAnimationInternal.h 12KB
AMapSearchAPI.h 11KB
TransformationMatrix.h 11KB
UIButton+WebCache.h 11KB
SDWebImageManager.h 10KB
SVProgressHUD.h 10KB
UIButton+AFNetworking.h 10KB
共 1332 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功