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
没有合适的资源?快使用搜索试试~ 我知道了~
ios-方钉钉的通讯录.zip
共84个文件
h:35个
m:33个
plist:2个
需积分: 10 5 下载量 18 浏览量
2019-07-11
19:38:05
上传
评论
收藏 235KB ZIP 举报
温馨提示
方钉钉的通讯录
资源推荐
资源详情
资源评论
收起资源包目录
7b1f73ab197e9eff32d447081ddce16d.zip (84个子文件)
AddressBookDome
.DS_Store 6KB
AddressBookDome.xcodeproj
project.xcworkspace
contents.xcworkspacedata 160B
xcuserdata
mhome.xcuserdatad
UserInterfaceState.xcuserstate 24KB
xcuserdata
mhome.xcuserdatad
xcdebugger
Breakpoints_v2.xcbkptlist 5KB
xcschemes
xcschememanagement.plist 487B
AddressBookDome.xcscheme 3KB
project.pbxproj 38KB
AddressBookDome
OrganizationModel.h 575B
ViewController.m 4KB
PersonnelModel.h 1KB
Info.plist 1KB
dataModel.h 723B
dingdingHelper.h 303B
dataModel.m 211B
main.m 336B
TwoViewController.m 831B
btn_info_right@2x.png 1KB
YSNetworkManager.m 4KB
UIView+Utils.m 6KB
YSDataManager.h 1KB
Base.lproj
LaunchScreen.storyboard 2KB
Main.storyboard 2KB
YYModel
LICENSE 1KB
YYModel
YYModel.h 595B
NSObject+YYModel.h 13KB
YYClassInfo.m 13KB
YYClassInfo.h 8KB
NSObject+YYModel.m 83KB
README.md 16KB
YSNetworkManager.h 1KB
dingdingHelper.m 449B
UIView+Utils.h 3KB
tabber_icon_inquiry_pre@2x.png 3KB
ViewController.h 217B
AppDelegate.h 279B
YSNationalWay.m 1KB
FirstViewController.m 11KB
MyScrollView.h 411B
OrganizationModel.m 213B
Assets.xcassets
AppIcon.appiconset
Contents.json 585B
TwoViewController.h 271B
FirstViewController.h 397B
AFNetworking
Security
AFSecurityPolicy.h 5KB
AFSecurityPolicy.m 11KB
Reachability
AFNetworkReachabilityManager.h 8KB
AFNetworkReachabilityManager.m 10KB
AFNetworking.h 2KB
UIKit
UIProgressView+AFNetworking.h 3KB
UIActivityIndicatorView+AFNetworking.m 4KB
UIKit+AFNetworking.h 2KB
UIAlertView+AFNetworking.m 6KB
UIImageView+AFNetworking.m 8KB
UIActivityIndicatorView+AFNetworking.h 2KB
AFNetworkActivityIndicatorManager.m 6KB
UIProgressView+AFNetworking.m 8KB
UIRefreshControl+AFNetworking.h 2KB
UIRefreshControl+AFNetworking.m 4KB
UIAlertView+AFNetworking.h 5KB
AFNetworkActivityIndicatorManager.h 4KB
UIButton+AFNetworking.h 9KB
UIButton+AFNetworking.m 10KB
UIImageView+AFNetworking.h 7KB
UIWebView+AFNetworking.m 6KB
UIWebView+AFNetworking.h 6KB
NSURLConnection
AFHTTPRequestOperation.h 4KB
AFHTTPRequestOperationManager.m 10KB
AFURLConnectionOperation.m 27KB
AFHTTPRequestOperationManager.h 19KB
AFURLConnectionOperation.h 17KB
AFHTTPRequestOperation.m 7KB
Serialization
AFURLResponseSerialization.h 11KB
AFURLResponseSerialization.m 27KB
AFURLRequestSerialization.h 21KB
AFURLRequestSerialization.m 50KB
NSURLSession
AFURLSessionManager.h 29KB
AFURLSessionManager.m 43KB
AFHTTPSessionManager.m 12KB
AFHTTPSessionManager.h 14KB
YSNationalWay.h 2KB
YSDataManager.m 8KB
PersonnelModel.m 204B
server.cer 1KB
AppDelegate.m 2KB
MyScrollView.m 2KB
共 84 条
- 1
资源评论
weixin_39841848
- 粉丝: 509
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于JavaScript 实现的KMP 算法
- 基于C++实现二叉树的创建,遍历,添加,查找与删除
- 基于C语言实现二叉树的基本操作
- 毕业设计基于STM32的测量温度与压力的数据处理设计C语言完整源码+论文.zip
- 基于MATLAB的PCA算法人脸识别项目源码+GUI界面+说明文档.zip
- 基于STM32的测量温度与压力的数据处理设计源码+论文(毕业设计).zip
- Vision Transformer 网络对不同氨气氧气浓度轨迹RAS 图像数据集的分类,包含训练权重和数据集、迁移学习
- 基于C51带字库LCD12864(ST7920)的keil工程源码,只支持8位并口通讯(不支持串口),可显示中文.zip
- 基于SI4463射频模块433MD-SMA无线模块软硬件技术资料及(SI4463)IC技术资料文档.zip
- (GPS+北斗+GSM)HLK-GS2503模块软硬件开发资料包硬件参考设计(原理图PCB)+技术文档资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功