Commit a9369fcf authored by 曹云霄's avatar 曹云霄

适配IOS10,并修复由后台进入前台崩溃,修复工程警告

No related merge requests found
......@@ -441,7 +441,7 @@
} WithprogressBlock:^(double progress) {
if (progress >= 1) {
dispatch_async(dispatch_get_main_queue(), ^{
weskSelf.TCHud.labelText = @"上传完成";
weskSelf.TCHud.label.text = @"上传完成";
[weskSelf RemoveMBProgressHUDLoding];
});
}else
......@@ -452,12 +452,12 @@
}
} WithErrorCodeBlock:^(id errorCodeValue) {
dispatch_async(dispatch_get_main_queue(), ^{
weskSelf.TCHud.labelText = @"上传失败";
weskSelf.TCHud.label.text = @"上传失败";
[weskSelf RemoveMBProgressHUDLoding];
});
} WithFailureBlock:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
weskSelf.TCHud.labelText = @"上传失败";
weskSelf.TCHud.label.text = @"上传失败";
[weskSelf RemoveMBProgressHUDLoding];
});
}];
......
......@@ -260,7 +260,7 @@
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
OrderdetailsViewController *orderdetails = [storyboard instantiateViewControllerWithIdentifier:@"orderdetails"];
TOOrderEntity *model = [[self.orderRecordArray objectAtIndex_opple:indexPath.row] order];
TOOrderEntity *model = (TOOrderEntity *)[[self.orderRecordArray objectAtIndex_opple:indexPath.row] order];
orderdetails.orderCode = model.orderNumber;
orderdetails.sectionTitle = @[@"订单信息",@"客户信息",@"收货信息",@"商品信息",@"附件信息"];
orderdetails.isShowattachment = YES;
......
......@@ -41,22 +41,14 @@ static NSString * const reuseIdentifier = @"Cell";
{
// 创建一个流水布局
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
// 设置cell的尺寸
layout.itemSize = [UIScreen mainScreen].bounds.size;
// 设置滚动的方向
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
// 行间距
layout.minimumLineSpacing = 0;
// 设置cell之间的间距
layout.minimumInteritemSpacing = 0;
//
// // 组间距
// layout.sectionInset = UIEdgeInsetsMake(100, 20, 0, 30);
return [super initWithCollectionViewLayout:layout];
}
......@@ -197,7 +189,6 @@ static NSString * const reuseIdentifier = @"Cell";
self.backButton.frame = frame;
}];
}
}else
{
......@@ -210,7 +201,6 @@ static NSString * const reuseIdentifier = @"Cell";
self.backView.frame = frame;
}];
}else if (self.backView.frame.origin.y == -64)
{
[UIView animateWithDuration:0.3 animations:^{
......@@ -221,53 +211,7 @@ static NSString * const reuseIdentifier = @"Cell";
}];
}
}
}
#pragma mark <UICollectionViewDelegate>
/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
return NO;
}
- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
......@@ -129,16 +129,15 @@
if (self.userName.text.length == 0) {
[self ErrorMBProgressView:@"用户名不能为空"];
return;
}else if (self.passWord.text.length == 0)
{
[self ErrorMBProgressView:@"密码不能为空"];
return;
}
[self judgeUserNameAndPassword];
}
#pragma mark -设置根视图控制器
......@@ -293,13 +292,9 @@
#pragma mark -忘记密码
- (IBAction)ForgotpasswordButtonClick:(UIButton *)sender {
self.identityView = [[[NSBundle mainBundle] loadNibNamed:@"authenticateView" owner:self options:nil]firstObject];
//判断登陆界面是否已经输入了用户名,如果有则直接引用,否则报错
if (self.userName.text.length != 0) {
self.identityView.userName.text = self.userName.text;
} else {
......@@ -316,7 +311,6 @@
self.identityView.frame = self.userNameLoginView.frame;
[self.view addSubview:self.identityView];
[UIView animateWithDuration:0.2 animations:^{
self.identityView.alpha = 1;
}];
}
......@@ -326,12 +320,10 @@
{
NSString *inputPhoneNumber = self.identityView.bindingPhoneNumber.text;
if (inputPhoneNumber.length == 0) {
[self ErrorMBProgressView:@"手机号不能为空"];
return;
}
if (![HENLENSONG isValidateMobile:inputPhoneNumber]) {
[self ErrorMBProgressView:@"手机号码格式不正确"];
return;
}
......@@ -339,10 +331,8 @@
//发送验证码
NSString *urlString = [NSString stringWithFormat:SERVERREQUESTURL(SENDSMS),inputPhoneNumber,self.identityView.userName.text];
[[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:urlString WithRequestType:1 WithParameter:nil WithReturnValueBlock:^(id returnValue) {
[self RemoveMBProgressHUDLoding];
if ([returnValue[@"code"] isEqualToNumber:@0]) {
[self ErrorMBProgressView:@"发送验证码成功"];
[self.identityView.SendButton setTitle:@"60" forState:UIControlStateNormal];
self.identityView.SendButton.enabled = NO;
......@@ -351,14 +341,10 @@
{
[self ErrorMBProgressView:returnValue[@"message"]];
}
} WithErrorCodeBlock:^(id errorCodeValue) {
[self RemoveMBProgressHUDLoding];
[self ErrorMBProgressView:@"网络中断"];
} WithFailureBlock:^(NSError *error) {
[self ErrorMBProgressView:error.localizedDescription];
[self RemoveMBProgressHUDLoding];
}];
......@@ -369,10 +355,8 @@
#pragma mark -倒计时
- (void)SendbuttonChangetitle
{
NSInteger number = [self.identityView.SendButton.currentTitle integerValue];
if (number <= 0) {
[self.identityView.SendButton setTitle:@"发送" forState:UIControlStateNormal];
self.identityView.SendButton.enabled = YES;
[self.sendTimer invalidate];
......@@ -387,15 +371,10 @@
#pragma mark -返回登陆界面
- (void)BackloginButtonClick
{
[UIView animateWithDuration:0.2 animations:^{
self.identityView.alpha = 0;
}completion:^(BOOL finished) {
[self.identityView removeFromSuperview];
}];
}
......@@ -405,7 +384,6 @@
{
// 验证码必须填写
if (self.identityView.verificationCode.text.length == 0) {
[self ErrorMBProgressView:@"验证码不能为空"];
return;
......@@ -434,13 +412,11 @@
[self ErrorMBProgressView:@"新密码为空"];
return;
}else if (self.resetPasswordView.confirmNewpass.text.length == 0)
{
[self ErrorMBProgressView:@"确认密码为空"];
return;
}
if (![self.resetPasswordView.newpass.text isEqualToString:self.resetPasswordView.confirmNewpass.text]) {
[self ErrorMBProgressView:@"两次密码不相同"];
......@@ -481,19 +457,14 @@
- (void)backButonClick
{
[UIView animateWithDuration:0.2 animations:^{
self.resetPasswordView.alpha = 0;
} completion:^(BOOL finished) {
[self.resetPasswordView removeFromSuperview];
}];
// 重置发送按钮
[self.identityView.SendButton setTitle:@"发送" forState:UIControlStateNormal];
self.identityView.SendButton.enabled = YES;
[self.sendTimer invalidate];
// 清空验证码
self.identityView.verificationCode.text = @"";
}
......
......@@ -205,14 +205,14 @@
if (![Shoppersmanager manager].currentCustomer) {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
hud.labelText = @"必须设置当前客户才能访问购物车";
hud.label.text = @"必须设置当前客户才能访问购物车";
hud.margin = 10.f;
hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
hud.bezelView.color = [UIColor whiteColor];
hud.minSize = CGSizeMake(200, 50);
hud.animationType = MBProgressHUDAnimationZoom;
hud.mode = MBProgressHUDModeText;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:1.0f];
[hud hideAnimated:YES afterDelay:1.0f];
}else
{
......@@ -346,14 +346,14 @@
if (![Shoppersmanager manager].currentCustomer) {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
hud.labelText = @"必须设置当前客户才能访问购物车";
hud.label.text = @"必须设置当前客户才能访问购物车";
hud.margin = 10.f;
hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
hud.bezelView.color = [UIColor whiteColor];
hud.minSize = CGSizeMake(200, 50);
hud.animationType = MBProgressHUDAnimationZoom;
hud.mode = MBProgressHUDModeText;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:1.0f];
[hud hideAnimated:YES afterDelay:1.0f];
}else
{
......
......@@ -146,7 +146,7 @@
if (progress >= 1) {
dispatch_async(dispatch_get_main_queue(), ^{
self.TCHud.labelText = @"上传完成";
self.TCHud.label.text = @"上传完成";
[self RemoveMBProgressHUDLoding];
});
}else
......@@ -157,12 +157,12 @@
}
} WithErrorCodeBlock:^(id errorCodeValue) {
dispatch_async(dispatch_get_main_queue(), ^{
self.TCHud.labelText = @"上传失败";
self.TCHud.label.text = @"上传失败";
[self RemoveMBProgressHUDLoding];
});
} WithFailureBlock:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
self.TCHud.labelText = @"上传失败";
self.TCHud.label.text = @"上传失败";
[self RemoveMBProgressHUDLoding];
});
}];
......
......@@ -1825,10 +1825,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: 云霄 曹 (WM8ZU7YY98)";
COMPRESS_PNG_FILES = NO;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/build/Debug-iphoneos",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SRCROOT)/Tools/PrefixHeader.pch";
INFOPLIST_FILE = Lighting/Info.plist;
......@@ -1886,10 +1883,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: 云霄 曹 (WM8ZU7YY98)";
COMPRESS_PNG_FILES = NO;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/build/Debug-iphoneos",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SRCROOT)/Tools/PrefixHeader.pch";
INFOPLIST_FILE = Lighting/Info.plist;
......
......@@ -61,7 +61,19 @@
ReferencedContainer = "container:Lighting.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "Trash.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Trash@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
Lighting/Images.xcassets/Trash.imageset/Trash.png

1.25 KB

Lighting/Images.xcassets/Trash.imageset/Trash@2x.png

1.54 KB

{
"images" : [
{
"idiom" : "universal",
"filename" : "bg.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "bg@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
Lighting/Images.xcassets/bg.imageset/bg.png

1.37 KB

Lighting/Images.xcassets/bg.imageset/bg@2x.png

1.81 KB

......@@ -76,6 +76,8 @@
<array>
<string>armv7</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarHidden</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
......
......@@ -1328,21 +1328,21 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="规格:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="2HG-A6-myN">
<rect key="frame" x="312" y="8" width="42" height="21"/>
<rect key="frame" x="312" y="8" width="50" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="功率:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="0MW-YH-UQn">
<rect key="frame" x="312" y="42" width="42" height="21"/>
<rect key="frame" x="312" y="42" width="50" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="尺寸:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="alp-Lq-QHV">
<rect key="frame" x="312" y="75" width="42" height="21"/>
<rect key="frame" x="312" y="75" width="50" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
......@@ -1356,28 +1356,28 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="材质:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="2nC-CJ-ic4">
<rect key="frame" x="596" y="8" width="42" height="21"/>
<rect key="frame" x="596" y="8" width="50" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="系列:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="tsu-li-rkc">
<rect key="frame" x="596" y="42" width="42" height="21"/>
<rect key="frame" x="596" y="42" width="50" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="功能:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="VYe-Iv-mxy">
<rect key="frame" x="596" y="75" width="42" height="21"/>
<rect key="frame" x="596" y="75" width="50" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="空间:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="p3d-XA-46m">
<rect key="frame" x="596" y="108" width="42" height="21"/>
<rect key="frame" x="596" y="108" width="50" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
......@@ -3693,31 +3693,6 @@
</objects>
<point key="canvasLocation" x="1824" y="11931"/>
</scene>
<!--Full Screen View Controller-->
<scene sceneID="3Qc-Do-TNO">
<objects>
<collectionViewController id="yxY-JW-6On" customClass="FullScreenViewController" sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="zbz-Hc-sIU">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="Y3a-nU-d5W">
<size key="itemSize" width="530" height="360"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells/>
<connections>
<outlet property="dataSource" destination="yxY-JW-6On" id="USI-4M-Jxb"/>
<outlet property="delegate" destination="yxY-JW-6On" id="Ost-SA-4kh"/>
</connections>
</collectionView>
<navigationItem key="navigationItem" id="xQs-q7-nPf"/>
</collectionViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qxC-eM-cdf" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1824" y="13177"/>
</scene>
<!--Experience Centre View Controller-->
<scene sceneID="LfM-Vg-riy">
<objects>
......
......@@ -14,13 +14,13 @@ PODS:
- AFNetworking/Serialization (3.1.0)
- AFNetworking/UIKit (3.1.0):
- AFNetworking/NSURLSession
- Bugly (2.2.3)
- Bugly (2.4.0)
- DZNEmptyDataSet (1.8.1)
- FDFullscreenPopGesture (1.1)
- IQKeyboardManager (4.0.4)
- JSONModel (1.2.0)
- Masonry (0.6.4)
- MBProgressHUD (0.9.2)
- IQKeyboardManager (4.0.6)
- JSONModel (1.5.1)
- Masonry (1.0.2)
- MBProgressHUD (1.0.0)
- MJExtension (3.0.13)
- MJRefresh (3.1.12)
- MMDrawerController (0.6.0):
......@@ -35,42 +35,39 @@ PODS:
- MMDrawerController/Core
- MMDrawerController/Subclass (0.6.0):
- MMDrawerController/Core
- SDWebImage (3.7.6):
- SDWebImage/Core (= 3.7.6)
- SDWebImage/Core (3.7.6)
- SVProgressHUD (2.0.3)
- SDWebImage (3.8.2):
- SDWebImage/Core (= 3.8.2)
- SDWebImage/Core (3.8.2)
- UMengSocial (5.0)
DEPENDENCIES:
- AFNetworking (~> 3.1.0)
- Bugly (~> 2.2.3)
- DZNEmptyDataSet (~> 1.8.1)
- FDFullscreenPopGesture (~> 1.1)
- IQKeyboardManager (~> 4.0.0)
- JSONModel (~> 1.2.0)
- Masonry (~> 0.6.4)
- MBProgressHUD (~> 0.9.2)
- MJExtension (~> 3.0.10)
- MJRefresh (~> 3.1.0)
- MMDrawerController (~> 0.6.0)
- SDWebImage (~> 3.7.5)
- SVProgressHUD (~> 2.0.3)
- UMengSocial (~> 5.0)
- AFNetworking
- Bugly
- DZNEmptyDataSet
- FDFullscreenPopGesture
- IQKeyboardManager
- JSONModel
- Masonry
- MBProgressHUD
- MJExtension
- MJRefresh
- MMDrawerController
- SDWebImage
- UMengSocial
SPEC CHECKSUMS:
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
Bugly: db578ea92b2a6b132cc19f79adf3bcd3b0fe6769
Bugly: 3b56d8365c5687f74fd6fbb50c5b7ede3cdac96c
DZNEmptyDataSet: 9525833b9e68ac21c30253e1d3d7076cc828eaa7
FDFullscreenPopGesture: a8a620179e3d9c40e8e00256dcee1c1a27c6d0f0
IQKeyboardManager: 4a6f83b540283c2645aaeba2bd8dc0f09b5c77f8
JSONModel: 12523685c4b623553ccf844bbbf7007624317b2c
Masonry: 281802d04d787ea2973179ee8bcb50500579ede2
MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1
IQKeyboardManager: c52debb1967799ae7addb98eab0cf328083a874f
JSONModel: fd2553dc9e6608a3f35bfc956a14be35395d3852
Masonry: 7c429b56da9d4ee0bbb3ed77a5ea710d6a5df39e
MBProgressHUD: 4890f671c94e8a0f3cf959aa731e9de2f036d71a
MJExtension: 5932755f451458eefa24239358817f8d291240c7
MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806
MMDrawerController: e3a54a5570388463ad3b36975251575b50c4e1a0
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
SVProgressHUD: b0830714205bea1317ea1a2ebc71e5633af334d4
SDWebImage: 098e97e6176540799c27e804c96653ee0833d13c
UMengSocial: 48b67179c492a8cf7803fbb0438b8f55432e2fc1
COCOAPODS: 0.39.0
No preview for this file type
......@@ -2,7 +2,7 @@
// Bugly.h
// Bugly
//
// Version: 2.2(3)
// Version: 2.4(0)
//
// Copyright (c) 2016年 Bugly. All rights reserved.
//
......@@ -32,6 +32,17 @@ BLY_START_NONNULL
+ (void)startWithAppId:(NSString * BLY_NULLABLE)appId
config:(BuglyConfig * BLY_NULLABLE)config;
/**
* 使用指定配置初始化Bugly
*
* @param appId 注册Bugly分配的应用唯一标识
* @param developmentDevice 是否开发设备
* @param config 传入配置的 BuglyConfig
*/
+ (void)startWithAppId:(NSString * BLY_NULLABLE)appId
developmentDevice:(BOOL)development
config:(BuglyConfig * BLY_NULLABLE)config;
/**
* 设置用户标识
*
......
......@@ -108,6 +108,17 @@ BLY_START_NONNULL
*/
@property (nonatomic, assign) BuglyLogLevel reportLogLevel;
BLY_END_NONNULL
/**
* 崩溃数据过滤器,如果崩溃堆栈的模块名包含过滤器中设置的关键字,则崩溃数据不会进行上报
* 例如,过滤崩溃堆栈中包含搜狗输入法的数据,可以添加过滤器关键字SogouInputIPhone.dylib等
*/
@property (nonatomic, copy) NSArray * excludeModuleFilter;
/**
* 控制台日志上报开关,默认关闭
*/
@property (nonatomic, assign) BOOL consolelogEnable;
@end
BLY_END_NONNULL
......@@ -46,7 +46,7 @@ FOUNDATION_EXPORT void BLYLogv(BuglyLogLevel level, NSString *format, va_list ar
/**
* @brief 打印BLYLogLevelInfo日志
*
* @param format 日志内容
* @param fmt 日志内容 总日志大小限制为:字符串长度30k,条数200
*/
+ (void)log:(NSString *)format, ...;
......@@ -54,7 +54,7 @@ FOUNDATION_EXPORT void BLYLogv(BuglyLogLevel level, NSString *format, va_list ar
* @brief 打印日志
*
* @param level 日志级别
* @param fmt 日志内容
* @param fmt 日志内容 总日志大小限制为:字符串长度30k,条数200
*/
+ (void)level:(BuglyLogLevel) level logs:(NSString *)message;
......@@ -62,7 +62,7 @@ FOUNDATION_EXPORT void BLYLogv(BuglyLogLevel level, NSString *format, va_list ar
* @brief 打印日志
*
* @param level 日志级别
* @param fmt 日志内容
* @param fmt 日志内容 总日志大小限制为:字符串长度30k,条数200
*/
+ (void)level:(BuglyLogLevel) level log:(NSString *)format, ...;
......@@ -71,7 +71,7 @@ FOUNDATION_EXPORT void BLYLogv(BuglyLogLevel level, NSString *format, va_list ar
*
* @param level 日志级别
* @param tag 日志模块分类
* @param format 日志内容
* @param fmt 日志内容 总日志大小限制为:字符串长度30k,条数200
*/
+ (void)level:(BuglyLogLevel) level tag:(NSString *) tag log:(NSString *)format, ...;
......
../../../JSONModel/JSONModel/JSONModel/JSONModelArray.h
\ No newline at end of file
../../../JSONModel/JSONModel/JSONModelCategories/NSArray+JSONModel.h
\ No newline at end of file
../../../SVProgressHUD/SVProgressHUD/SVIndefiniteAnimatedView.h
\ No newline at end of file
../../../SVProgressHUD/SVProgressHUD/SVProgressAnimatedView.h
\ No newline at end of file
../../../SVProgressHUD/SVProgressHUD/SVProgressHUD.h
\ No newline at end of file
../../../SVProgressHUD/SVProgressHUD/SVRadialGradientLayer.h
\ No newline at end of file
../../../JSONModel/JSONModel/JSONModel/JSONModelArray.h
\ No newline at end of file
../../../JSONModel/JSONModel/JSONModelCategories/NSArray+JSONModel.h
\ No newline at end of file
../../../SVProgressHUD/SVProgressHUD/SVIndefiniteAnimatedView.h
\ No newline at end of file
../../../SVProgressHUD/SVProgressHUD/SVProgressAnimatedView.h
\ No newline at end of file
../../../SVProgressHUD/SVProgressHUD/SVProgressHUD.h
\ No newline at end of file
../../../SVProgressHUD/SVProgressHUD/SVRadialGradientLayer.h
\ No newline at end of file
......@@ -38,29 +38,6 @@
@implementation UIView (IQ_UIView_Hierarchy)
//Special textFields,textViews,scrollViews
Class UIAlertSheetTextFieldClass; //UIAlertView
Class UIAlertSheetTextFieldClass_iOS8; //UIAlertView
Class UITableViewCellScrollViewClass; //UITableViewCell
Class UITableViewWrapperViewClass; //UITableViewCell
Class UIQueuingScrollViewClass; //UIPageViewController
Class UISearchBarTextFieldClass; //UISearchBar
+(void)initialize
{
[super initialize];
UIAlertSheetTextFieldClass = NSClassFromString(@"UIAlertSheetTextField");
UIAlertSheetTextFieldClass_iOS8 = NSClassFromString(@"_UIAlertControllerTextField");
UITableViewCellScrollViewClass = NSClassFromString(@"UITableViewCellScrollView");
UITableViewWrapperViewClass = NSClassFromString(@"UITableViewWrapperView");
UIQueuingScrollViewClass = NSClassFromString(@"_UIQueuingScrollView");
UISearchBarTextFieldClass = NSClassFromString(@"UISearchBarTextField");
}
-(void)_setIsAskingCanBecomeFirstResponder:(BOOL)isAskingCanBecomeFirstResponder
{
......@@ -126,6 +103,16 @@ Class UISearchBarTextFieldClass; //UISearchBar
while (superview)
{
static Class UITableViewCellScrollViewClass; //UITableViewCell
static Class UITableViewWrapperViewClass; //UITableViewCell
static Class UIQueuingScrollViewClass; //UIPageViewController
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UITableViewCellScrollViewClass = NSClassFromString(@"UITableViewCellScrollView");
UITableViewWrapperViewClass = NSClassFromString(@"UITableViewWrapperView");
UIQueuingScrollViewClass = NSClassFromString(@"_UIQueuingScrollView");
});
if ([superview isKindOfClass:classType] &&
([superview isKindOfClass:UITableViewCellScrollViewClass] == NO) &&
([superview isKindOfClass:UITableViewWrapperViewClass] == NO) &&
......@@ -169,7 +156,7 @@ Class UISearchBarTextFieldClass; //UISearchBar
//Array of (UITextField/UITextView's).
NSMutableArray *tempTextFields = [[NSMutableArray alloc] init];
for (UITextField *textField in siblings)
for (UIView *textField in siblings)
if ([textField _IQcanBecomeFirstResponder])
[tempTextFields addObject:textField];
......@@ -180,10 +167,7 @@ Class UISearchBarTextFieldClass; //UISearchBar
{
NSMutableArray *textFields = [[NSMutableArray alloc] init];
//subviews are returning in opposite order. So I sorted it according the frames 'y'.
NSArray *subViews = [self.subviews sortedArrayByPosition];
for (UITextField *textField in subViews)
for (UIView *textField in self.subviews)
{
if ([textField _IQcanBecomeFirstResponder])
{
......@@ -196,6 +180,29 @@ Class UISearchBarTextFieldClass; //UISearchBar
}
}
//subviews are returning in incorrect order. Sorting according the frames 'y'.
return [textFields sortedArrayUsingComparator:^NSComparisonResult(UIView *view1, UIView *view2) {
CGRect frame1 = [view1 convertRect:view1.bounds toView:self];
CGRect frame2 = [view2 convertRect:view2.bounds toView:self];
CGFloat x1 = CGRectGetMinX(frame1);
CGFloat y1 = CGRectGetMinY(frame1);
CGFloat x2 = CGRectGetMinX(frame2);
CGFloat y2 = CGRectGetMinY(frame2);
if (y1 < y2) return NSOrderedAscending;
else if (y1 > y2) return NSOrderedDescending;
//Else both y are same so checking for x positions
else if (x1 < x2) return NSOrderedAscending;
else if (x1 > x2) return NSOrderedDescending;
else return NSOrderedSame;
}];
return textFields;
}
......@@ -305,11 +312,27 @@ Class UISearchBarTextFieldClass; //UISearchBar
-(BOOL)isSearchBarTextField
{
static Class UISearchBarTextFieldClass; //UISearchBar
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UISearchBarTextFieldClass = NSClassFromString(@"UISearchBarTextField");
});
return ([self isKindOfClass:UISearchBarTextFieldClass] || [self isKindOfClass:[UISearchBar class]]);
}
-(BOOL)isAlertViewTextField
{
//Special textFields,textViews,scrollViews
static Class UIAlertSheetTextFieldClass; //UIAlertView
static Class UIAlertSheetTextFieldClass_iOS8; //UIAlertView
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIAlertSheetTextFieldClass = NSClassFromString(@"UIAlertSheetTextField");
UIAlertSheetTextFieldClass_iOS8 = NSClassFromString(@"_UIAlertControllerTextField");
});
return ([self isKindOfClass:UIAlertSheetTextFieldClass] || [self isKindOfClass:UIAlertSheetTextFieldClass_iOS8]);
}
......
......@@ -45,4 +45,12 @@ typedef NS_ENUM(NSInteger, IQLayoutGuidePosition) {
IQLayoutGuidePositionBottom,
};
//Xcode 8 compatibility check
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
#define IQ_IS_IOS10_OR_GREATER (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max)
#else
#define IQ_IS_IOS10_OR_GREATER NO
#endif
#endif
......@@ -83,6 +83,17 @@ extern NSInteger const kIQPreviousNextButtonToolbarTag;
*/
- (void)reloadLayoutIfNeeded;
/**
Boolean to know if keyboard is showing.
*/
@property(nonatomic, assign, readonly, getter = isKeyboardShowing) BOOL keyboardShowing;
/**
moved distance to the top used to maintain distance between keyboard and textField. Most of the time this will be a positive value.
*/
@property(nonatomic, assign, readonly) CGFloat movedDistance;
///-------------------------
/// @name IQToolbar handling
///-------------------------
......
......@@ -57,14 +57,18 @@ NSString *const kIQTextFieldReturnKeyType = @"kIQTextFieldReturnKeyType";
return self;
}
-(instancetype)initWithViewController:(UIViewController*)controller
-(instancetype)initWithViewController:(nullable UIViewController*)controller
{
self = [super init];
if (self)
{
textFieldInfoCache = [[NSMutableSet alloc] init];
[self addResponderFromView:controller.view];
if (controller.view)
{
[self addResponderFromView:controller.view];
}
}
return self;
......@@ -99,7 +103,7 @@ NSString *const kIQTextFieldReturnKeyType = @"kIQTextFieldReturnKeyType";
if (dict)
{
textField.keyboardType = [dict[kIQTextFieldReturnKeyType] integerValue];
textField.returnKeyType = [dict[kIQTextFieldReturnKeyType] integerValue];
textField.delegate = dict[kIQTextFieldDelegate];
[textFieldInfoCache removeObject:dict];
}
......@@ -168,7 +172,7 @@ NSString *const kIQTextFieldReturnKeyType = @"kIQTextFieldReturnKeyType";
#pragma mark - Goto next or Resign.
-(void)goToNextResponderOrResign:(UIView*)textField
-(BOOL)goToNextResponderOrResign:(UIView*)textField
{
UIView *superConsideredView;
......@@ -215,7 +219,16 @@ NSString *const kIQTextFieldReturnKeyType = @"kIQTextFieldReturnKeyType";
NSUInteger index = [textFields indexOfObject:textField];
//If it is not last textField. then it's next object becomeFirstResponder.
(index != NSNotFound && index < textFields.count-1) ? [textFields[index+1] becomeFirstResponder] : [textField resignFirstResponder];
if (index != NSNotFound && index < textFields.count-1)
{
[textFields[index+1] becomeFirstResponder];
return NO;
}
else
{
[textField resignFirstResponder];
return YES;
}
}
#pragma mark - TextField delegate
......@@ -267,17 +280,22 @@ NSString *const kIQTextFieldReturnKeyType = @"kIQTextFieldReturnKeyType";
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
BOOL shouldReturn = YES;
if ([self.delegate respondsToSelector:@selector(textFieldShouldReturn:)])
shouldReturn = [self.delegate textFieldShouldReturn:textField];
{
BOOL shouldReturn = [self.delegate textFieldShouldReturn:textField];
if (shouldReturn)
if (shouldReturn)
{
shouldReturn = [self goToNextResponderOrResign:textField];
}
return shouldReturn;
}
else
{
[self goToNextResponderOrResign:textField];
return [self goToNextResponderOrResign:textField];
}
return shouldReturn;
}
......@@ -321,7 +339,7 @@ NSString *const kIQTextFieldReturnKeyType = @"kIQTextFieldReturnKeyType";
if (shouldReturn && [text isEqualToString:@"\n"])
{
[self goToNextResponderOrResign:textView];
shouldReturn = [self goToNextResponderOrResign:textView];
}
return shouldReturn;
......@@ -360,7 +378,7 @@ NSString *const kIQTextFieldReturnKeyType = @"kIQTextFieldReturnKeyType";
for (NSDictionary *dict in textFieldInfoCache)
{
UITextField *textField = dict[kIQTextField];
textField.keyboardType = [dict[kIQTextFieldReturnKeyType] integerValue];
textField.returnKeyType = [dict[kIQTextFieldReturnKeyType] integerValue];
textField.delegate = dict[kIQTextFieldDelegate];
}
......
......@@ -25,7 +25,7 @@
#import "IQKeyboardManagerConstants.h"
#import "IQKeyboardManagerConstantsInternal.h"
#import <UIKit/UILabel.h>
#import <UIKIt/UIButton.h>
#import <UIKit/UIButton.h>
@implementation IQTitleBarButtonItem
{
......
......@@ -528,9 +528,20 @@
resourcesBundle = mainBundle;
}
UIImage *imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowLeft" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
UIImage *imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowRight" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
UIImage *imageLeftArrow = nil;
UIImage *imageRightArrow = nil;
if (IQ_IS_IOS10_OR_GREATER)
{
imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowUp" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowDown" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
}
else
{
imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowLeft" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowRight" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
}
//Support for RTL languages like Arabic, Persia etc... (Bug ID: #448)
if ([UIImage instancesRespondToSelector:@selector(imageFlippedForRightToLeftLayoutDirection)])
{
......@@ -545,7 +556,11 @@
//Fixed space
IQBarButtonItem *fixed =[[IQBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixed setWidth:20];
if (IQ_IS_IOS10_OR_GREATER) {
[fixed setWidth:6];
} else {
[fixed setWidth:20];
}
[items addObject:fixed];
//Next button
......@@ -623,8 +638,16 @@
resourcesBundle = mainBundle;
}
UIImage *imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowLeft" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
UIImage *imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowRight" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
UIImage *imageLeftArrow = nil;
UIImage *imageRightArrow = nil;
if (IQ_IS_IOS10_OR_GREATER) {
imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowUp" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowDown" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
} else {
imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowLeft" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowRight" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
}
//Support for RTL languages like Arabic, Persia etc... (Bug ID: #448)
if ([UIImage instancesRespondToSelector:@selector(imageFlippedForRightToLeftLayoutDirection)])
......@@ -640,7 +663,11 @@
//Fixed space
IQBarButtonItem *fixed =[[IQBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixed setWidth:20];
if (IQ_IS_IOS10_OR_GREATER) {
[fixed setWidth:6];
} else {
[fixed setWidth:20];
}
[items addObject:fixed];
//Next button
......@@ -714,8 +741,16 @@
resourcesBundle = mainBundle;
}
UIImage *imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowLeft" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
UIImage *imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowRight" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
UIImage *imageLeftArrow = nil;
UIImage *imageRightArrow = nil;
if (IQ_IS_IOS10_OR_GREATER) {
imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowUp" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowDown" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
} else {
imageLeftArrow = [UIImage imageNamed:@"IQButtonBarArrowLeft" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
imageRightArrow = [UIImage imageNamed:@"IQButtonBarArrowRight" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
}
//Support for RTL languages like Arabic, Persia etc... (Bug ID: #448)
if ([UIImage instancesRespondToSelector:@selector(imageFlippedForRightToLeftLayoutDirection)])
......@@ -731,7 +766,11 @@
//Fixed space
IQBarButtonItem *fixed =[[IQBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixed setWidth:20];
if (IQ_IS_IOS10_OR_GREATER) {
[fixed setWidth:6];
} else {
[fixed setWidth:20];
}
[items addObject:fixed];
//Next button
......
//
// JSONModelArray.h
//
// @version 0.8.0
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
/**
* **Don't make instances of JSONModelArray yourself, except you know what you are doing.**
*
* You get automatically JSONModelArray instances, when you declare a convert on demand property, like so:
*
* @property (strong, nonatomic) NSArray&lt;JSONModel, ConvertOnDemand&gt;* list;
*
* The class stores its contents as they come from JSON, and upon the first request
* of each of the objects stored in the array, it'll be converted to the target model class.
* Thus saving time upon the very first model creation.
*/
@interface JSONModelArray : NSObject <NSFastEnumeration>
/**
* Don't make instances of JSONModelArray yourself, except you know what you are doing.
*
* @param array an array of NSDictionary objects
* @param cls the JSONModel sub-class you'd like the NSDictionaries to be converted to on demand
*/
- (id)initWithArray:(NSArray *)array modelClass:(Class)cls;
- (id)objectAtIndex:(NSUInteger)index;
- (id)objectAtIndexedSubscript:(NSUInteger)index;
- (void)forwardInvocation:(NSInvocation *)anInvocation;
- (NSUInteger)count;
- (id)firstObject;
- (id)lastObject;
/**
* Looks up the array's contents and tries to find a JSONModel object
* with matching index property value to the indexValue param.
*
* Will return nil if no matching model is found. Will return nil if there's no index property
* defined on the models found in the array (will sample the first object, assuming the array
* contains homogeneous collection of objects)
*
* @param indexValue the id value to search for
* @return the found model or nil
*/
- (id)modelWithIndexValue:(id)indexValue;
@end
//
// JSONModelArray.m
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "JSONModelArray.h"
#import "JSONModel.h"
@implementation JSONModelArray
{
NSMutableArray* _storage;
Class _targetClass;
}
-(id)initWithArray:(NSArray *)array modelClass:(Class)cls
{
self = [super init];
if (self) {
_storage = [NSMutableArray arrayWithArray:array];
_targetClass = cls;
}
return self;
}
-(id)firstObject
{
return [self objectAtIndex:0];
}
-(id)lastObject
{
return [self objectAtIndex:_storage.count - 1];
}
-(id)objectAtIndex:(NSUInteger)index
{
return [self objectAtIndexedSubscript:index];
}
-(id)objectAtIndexedSubscript:(NSUInteger)index
{
id object = _storage[index];
if (![object isMemberOfClass:_targetClass]) {
NSError* err = nil;
object = [[_targetClass alloc] initWithDictionary:object error:&err];
if (object) {
_storage[index] = object;
}
}
return object;
}
-(void)forwardInvocation:(NSInvocation *)anInvocation
{
[anInvocation invokeWithTarget:_storage];
}
-(id)forwardingTargetForSelector:(SEL)selector
{
static NSArray *overriddenMethods = nil;
if (!overriddenMethods) overriddenMethods = @[@"initWithArray:modelClass:", @"objectAtIndex:", @"objectAtIndexedSubscript:", @"count", @"modelWithIndexValue:", @"description", @"mutableCopy", @"firstObject", @"lastObject", @"countByEnumeratingWithState:objects:count:"];
if ([overriddenMethods containsObject:NSStringFromSelector(selector)]) {
return self;
}
return _storage;
}
-(NSUInteger)count
{
return _storage.count;
}
-(id)modelWithIndexValue:(id)indexValue
{
if (self.count==0) return nil;
if (![_storage[0] indexPropertyName]) return nil;
for (JSONModel* model in _storage) {
if ([[model valueForKey:model.indexPropertyName] isEqual:indexValue]) {
return model;
}
}
return nil;
}
-(id)mutableCopy
{
//it's already mutable
return self;
}
#pragma mark - description
-(NSString*)description
{
NSMutableString* res = [NSMutableString stringWithFormat:@"<JSONModelArray[%@]>\n", [_targetClass description]];
for (id m in _storage) {
[res appendString: [m description]];
[res appendString: @",\n"];
}
[res appendFormat:@"\n</JSONModelArray>"];
return res;
}
-(NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
objects:(id __unsafe_unretained [])stackbuf
count:(NSUInteger)stackbufLength
{
NSUInteger count = 0;
unsigned long countOfItemsAlreadyEnumerated = state->state;
if (countOfItemsAlreadyEnumerated == 0) {
state->mutationsPtr = &state->extra[0];
}
if (countOfItemsAlreadyEnumerated < [self count]) {
state->itemsPtr = stackbuf;
while ((countOfItemsAlreadyEnumerated < [self count]) && (count < stackbufLength)) {
stackbuf[count] = [self objectAtIndex:countOfItemsAlreadyEnumerated];
countOfItemsAlreadyEnumerated++;
count++;
}
} else {
count = 0;
}
state->state = countOfItemsAlreadyEnumerated;
return count;
}
@end
//
// JSONModelClassProperty.h
// JSONModel
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
enum kCustomizationTypes {
kNotInspected = 0,
kCustom,
kNo
};
typedef enum kCustomizationTypes PropertyGetterType;
/**
* **You do not need to instantiate this class yourself.** This class is used internally by JSONModel
* to inspect the declared properties of your model class.
*
* Class to contain the information, representing a class property
* It features the property's name, type, whether it's a required property,
* It features the property's name, type, whether it's a required property,
* and (optionally) the class protocol
*/
@interface JSONModelClassProperty : NSObject
// deprecated
@property (assign, nonatomic) BOOL isIndex DEPRECATED_ATTRIBUTE;
/** The name of the declared property (not the ivar name) */
@property (copy, nonatomic) NSString* name;
@property (copy, nonatomic) NSString *name;
/** A property class type */
@property (assign, nonatomic) Class type;
/** Struct name if a struct */
@property (strong, nonatomic) NSString* structName;
@property (strong, nonatomic) NSString *structName;
/** The name of the protocol the property conforms to (or nil) */
@property (copy, nonatomic) NSString* protocol;
@property (copy, nonatomic) NSString *protocol;
/** If YES, it can be missing in the input data, and the input would be still valid */
@property (assign, nonatomic) BOOL isOptional;
......@@ -55,19 +39,10 @@ typedef enum kCustomizationTypes PropertyGetterType;
/** If YES - create a mutable object for the value of the property */
@property (assign, nonatomic) BOOL isMutable;
/** If YES - create models on demand for the array members */
@property (assign, nonatomic) BOOL convertsOnDemand;
/** If YES - the value of this property determines equality to other models */
@property (assign, nonatomic) BOOL isIndex;
/** The status of property getter introspection in a model */
@property (assign, nonatomic) PropertyGetterType getterType;
/** a custom getter for this property, found in the owning model */
@property (assign, nonatomic) SEL customGetter;
/** custom setters for this property, found in the owning model */
@property (strong, nonatomic) NSMutableDictionary<NSString *, id> *customSetters;
@property (strong, nonatomic) NSMutableDictionary *customSetters;
@end
//
// JSONModelClassProperty.m
// JSONModel
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "JSONModelClassProperty.h"
......@@ -22,11 +11,14 @@
{
//build the properties string for the current class property
NSMutableArray* properties = [NSMutableArray arrayWithCapacity:8];
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if (self.isIndex) [properties addObject:@"Index"];
#pragma GCC diagnostic pop
if (self.isOptional) [properties addObject:@"Optional"];
if (self.isMutable) [properties addObject:@"Mutable"];
if (self.convertsOnDemand) [properties addObject:@"ConvertOnDemand"];
if (self.isStandardJSONType) [properties addObject:@"Standard JSON type"];
if (self.customGetter) [properties addObject:[NSString stringWithFormat: @"Getter = %@", NSStringFromSelector(self.customGetter)]];
......@@ -42,12 +34,12 @@
[properties addObject:[NSString stringWithFormat: @"Setters = [%@]", [setters componentsJoinedByString:@", "]]];
}
NSString* propertiesString = @"";
if (properties.count>0) {
propertiesString = [NSString stringWithFormat:@"(%@)", [properties componentsJoinedByString:@", "]];
}
//return the name, type and additional properties
return [NSString stringWithFormat:@"@property %@%@ %@ %@",
self.type?[NSString stringWithFormat:@"%@*",self.type]:(self.structName?self.structName:@"primitive"),
......
//
// JSONModelError.h
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// JSONModel
//
#import <Foundation/Foundation.h>
/////////////////////////////////////////////////////////////////////////////////////////////
......@@ -28,15 +17,15 @@ typedef NS_ENUM(int, kJSONModelErrorTypes)
/////////////////////////////////////////////////////////////////////////////////////////////
/** The domain name used for the JSONModelError instances */
extern NSString* const JSONModelErrorDomain;
extern NSString *const JSONModelErrorDomain;
/**
/**
* If the model JSON input misses keys that are required, check the
* userInfo dictionary of the JSONModelError instance you get back -
* userInfo dictionary of the JSONModelError instance you get back -
* under the kJSONModelMissingKeys key you will find a list of the
* names of the missing keys.
*/
extern NSString* const kJSONModelMissingKeys;
extern NSString *const kJSONModelMissingKeys;
/**
* If JSON input has a different type than expected by the model, check the
......@@ -44,62 +33,62 @@ extern NSString* const kJSONModelMissingKeys;
* under the kJSONModelTypeMismatch key you will find a description
* of the mismatched types.
*/
extern NSString* const kJSONModelTypeMismatch;
extern NSString *const kJSONModelTypeMismatch;
/**
* If an error occurs in a nested model, check the userInfo dictionary of
* the JSONModelError instance you get back - under the kJSONModelKeyPath
* key you will find key-path at which the error occurred.
*/
extern NSString* const kJSONModelKeyPath;
extern NSString *const kJSONModelKeyPath;
/////////////////////////////////////////////////////////////////////////////////////////////
/**
* Custom NSError subclass with shortcut methods for creating
* Custom NSError subclass with shortcut methods for creating
* the common JSONModel errors
*/
@interface JSONModelError : NSError
@property (strong, nonatomic) NSHTTPURLResponse* httpResponse;
@property (strong, nonatomic) NSHTTPURLResponse *httpResponse;
@property (strong, nonatomic) NSData* responseData;
@property (strong, nonatomic) NSData *responseData;
/**
* Creates a JSONModelError instance with code kJSONModelErrorInvalidData = 1
*/
+(id)errorInvalidDataWithMessage:(NSString*)message;
+ (id)errorInvalidDataWithMessage:(NSString *)message;
/**
* Creates a JSONModelError instance with code kJSONModelErrorInvalidData = 1
* @param keys a set of field names that were required, but not found in the input
*/
+(id)errorInvalidDataWithMissingKeys:(NSSet*)keys;
+ (id)errorInvalidDataWithMissingKeys:(NSSet *)keys;
/**
* Creates a JSONModelError instance with code kJSONModelErrorInvalidData = 1
* @param mismatchDescription description of the type mismatch that was encountered.
*/
+(id)errorInvalidDataWithTypeMismatch:(NSString*)mismatchDescription;
+ (id)errorInvalidDataWithTypeMismatch:(NSString *)mismatchDescription;
/**
* Creates a JSONModelError instance with code kJSONModelErrorBadResponse = 2
*/
+(id)errorBadResponse;
+ (id)errorBadResponse;
/**
* Creates a JSONModelError instance with code kJSONModelErrorBadJSON = 3
*/
+(id)errorBadJSON;
+ (id)errorBadJSON;
/**
* Creates a JSONModelError instance with code kJSONModelErrorModelIsInvalid = 4
*/
+(id)errorModelIsInvalid;
+ (id)errorModelIsInvalid;
/**
* Creates a JSONModelError instance with code kJSONModelErrorNilInput = 5
*/
+(id)errorInputIsNil;
+ (id)errorInputIsNil;
/**
* Creates a new JSONModelError with the same values plus information about the key-path of the error.
......@@ -108,7 +97,7 @@ extern NSString* const kJSONModelKeyPath;
* This key contains the component string parameter. If the key is already present
* then the new error object has the component string prepended to the existing value.
*/
- (instancetype)errorByPrependingKeyPathComponent:(NSString*)component;
- (instancetype)errorByPrependingKeyPathComponent:(NSString *)component;
/////////////////////////////////////////////////////////////////////////////////////////////
@end
//
// JSONModelError.m
// JSONModel
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "JSONModelError.h"
......@@ -25,7 +14,7 @@ NSString* const kJSONModelKeyPath = @"kJSONModelKeyPath";
+(id)errorInvalidDataWithMessage:(NSString*)message
{
message = [NSString stringWithFormat:@"Invalid JSON data: %@", message];
message = [NSString stringWithFormat:@"Invalid JSON data: %@", message];
return [JSONModelError errorWithDomain:JSONModelErrorDomain
code:kJSONModelErrorInvalidData
userInfo:@{NSLocalizedDescriptionKey:message}];
......@@ -56,7 +45,7 @@ NSString* const kJSONModelKeyPath = @"kJSONModelKeyPath";
{
return [JSONModelError errorWithDomain:JSONModelErrorDomain
code:kJSONModelErrorBadJSON
userInfo:@{NSLocalizedDescriptionKey:@"Malformed JSON. Check the JSONModel data input."}];
userInfo:@{NSLocalizedDescriptionKey:@"Malformed JSON. Check the JSONModel data input."}];
}
+(id)errorModelIsInvalid
......
//
// NSArray+JSONModel.h
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
#import "JSONModel.h"
/**
* Exposes invisible JSONModelArray methods
*/
@interface NSArray(JSONModel)
/**
* Looks up the array's contents and tries to find a JSONModel object
* with matching index property value to the indexValue param.
*
* Will return nil if no matching model is found. Will return nil if there's no index property
* defined on the models found in the array (will sample the first object, assuming the array
* contains homogeneous collection of objects)
*
* @param indexValue the id value to search for
* @return the found model or nil
* @exception NSException throws exception if you call this method on an instance, which is not actually a JSONModelArray
*/
- (id)modelWithIndexValue:(id)indexValue;
@end
//
// NSArray+JSONModel.m
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "NSArray+JSONModel.h"
@implementation NSArray(JSONModel)
- (id)modelWithIndexValue:(id)indexValue
{
NSAssert(NO, @"call modelWithIndexValue: on a ConvertOnDemand property, which is defined like that: @property (strong, nonatomic) NSArray<MyModel, ConvertOnDemand>* list;");
return nil;
}
@end
//
// JSONModelLib.h
// JSONModel
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
//JSONModel transformations
// core
#import "JSONModel.h"
#import "JSONModelError.h"
// transformations
#import "JSONValueTransformer.h"
#import "JSONKeyMapper.h"
//basic JSONModel classes
#import "JSONModelError.h"
#import "JSONModelClassProperty.h"
#import "JSONModel.h"
//network classes
// networking (deprecated)
#import "JSONHTTPClient.h"
#import "JSONModel+networking.h"
#import "JSONAPI.h"
//models array
#import "NSArray+JSONModel.h"
#import "JSONModelArray.h"
//
// JSONAPI.h
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// JSONModel
//
#import <Foundation/Foundation.h>
#import "JSONHTTPClient.h"
/////////////////////////////////////////////////////////////////////////////////////////////
/**
* @discussion Class for working with JSON APIs. It builds upon the JSONHTTPClient class
* and facilitates making requests to the same web host. Also features helper
* method for making calls to a JSON RPC service
*/
DEPRECATED_ATTRIBUTE
@interface JSONAPI : NSObject
/////////////////////////////////////////////////////////////////////////////////////////////
/** @name Configuring the API */
/**
* Sets the API url
* @param base the API url as a string
*/
+(void)setAPIBaseURLWithString:(NSString*)base;
/**
* Sets the default content type for the requests/responses
* @param ctype The content-type as a string. Some possible types,
* depending on the service: application/json, text/json, x-application/javascript, etc.
*/
+(void)setContentType:(NSString*)ctype;
/////////////////////////////////////////////////////////////////////////////////////////////
/** @name Making GET API requests */
/**
* Makes an asynchronous GET request to the API
* @param path the URL path to add to the base API URL for this HTTP call
* @param params the variables to pass to the API
* @param completeBlock a JSONObjectBlock block to execute upon completion
*/
+(void)getWithPath:(NSString*)path andParams:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;
/////////////////////////////////////////////////////////////////////////////////////////////
/** @name Making POST API requests */
/**
* Makes a POST request to the API
* @param path the URL path to add to the base API URL for this HTTP call
* @param params the variables to pass to the API
* @param completeBlock a JSONObjectBlock block to execute upon completion
*/
+(void)postWithPath:(NSString*)path andParams:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;
/////////////////////////////////////////////////////////////////////////////////////////////
/** @name JSON RPC methods */
/**
* Makes an asynchronous JSON RPC request to the API. Read more: http://www.jsonrpc.org
* @param method the HTTP method name; GET or POST only
* @param args the list of arguments to pass to the API
* @param completeBlock JSONObjectBlock to execute upon completion
*/
+(void)rpcWithMethodName:(NSString*)method andArguments:(NSArray*)args completion:(JSONObjectBlock)completeBlock;
/** @name JSON RPC (2.0) request method */
/**
* Makes an asynchronous JSON RPC 2.0 request to the API. Read more: http://www.jsonrpc.org
* @param method the HTTP method name; GET or POST only
* @param params the params to pass to the API - an NSArray or an NSDictionary,
* depending whether you're using named or unnamed parameters
* @param completeBlock JSONObjectBlock to execute upon completion
*/
+(void)rpc2WithMethodName:(NSString*)method andParams:(id)params completion:(JSONObjectBlock)completeBlock;
/////////////////////////////////////////////////////////////////////////////////////////////
+ (void)setAPIBaseURLWithString:(NSString *)base DEPRECATED_ATTRIBUTE;
+ (void)setContentType:(NSString *)ctype DEPRECATED_ATTRIBUTE;
+ (void)getWithPath:(NSString *)path andParams:(NSDictionary *)params completion:(JSONObjectBlock)completeBlock DEPRECATED_ATTRIBUTE;
+ (void)postWithPath:(NSString *)path andParams:(NSDictionary *)params completion:(JSONObjectBlock)completeBlock DEPRECATED_ATTRIBUTE;
+ (void)rpcWithMethodName:(NSString *)method andArguments:(NSArray *)args completion:(JSONObjectBlock)completeBlock DEPRECATED_ATTRIBUTE;
+ (void)rpc2WithMethodName:(NSString *)method andParams:(id)params completion:(JSONObjectBlock)completeBlock DEPRECATED_ATTRIBUTE;
@end
//
// JSONAPI.m
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// JSONModel
//
#import "JSONAPI.h"
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wdeprecated-implementations"
#pragma mark - helper error model class
@interface JSONAPIRPCErrorModel: JSONModel
@property (assign, nonatomic) int code;
......@@ -26,6 +18,7 @@
#pragma mark - static variables
static JSONAPI* sharedInstance = nil;
static long jsonRpcId = 0;
#pragma mark - JSONAPI() private interface
......@@ -64,7 +57,7 @@ static long jsonRpcId = 0;
+(void)getWithPath:(NSString*)path andParams:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock
{
NSString* fullURL = [NSString stringWithFormat:@"%@%@", sharedInstance.baseURLString, path];
[JSONHTTPClient getJSONFromURLWithString: fullURL params:params completion:^(NSDictionary *json, JSONModelError *e) {
completeBlock(json, e);
}];
......@@ -74,7 +67,7 @@ static long jsonRpcId = 0;
+(void)postWithPath:(NSString*)path andParams:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock
{
NSString* fullURL = [NSString stringWithFormat:@"%@%@", sharedInstance.baseURLString, path];
[JSONHTTPClient postJSONFromURLWithString: fullURL params:params completion:^(NSDictionary *json, JSONModelError *e) {
completeBlock(json, e);
}];
......@@ -83,7 +76,7 @@ static long jsonRpcId = 0;
#pragma mark - RPC methods
+(void)__rpcRequestWithObject:(id)jsonObject completion:(JSONObjectBlock)completeBlock
{
NSData* jsonRequestData = [NSJSONSerialization dataWithJSONObject:jsonObject
options:kNilOptions
error:nil];
......@@ -111,7 +104,7 @@ static long jsonRpcId = 0;
e = [JSONModelError errorBadResponse];
}
}
//invoke the callback
completeBlock(result, e);
}
......@@ -122,7 +115,7 @@ static long jsonRpcId = 0;
{
NSAssert(method, @"No method specified");
if (!args) args = @[];
[self __rpcRequestWithObject:@{
//rpc 1.0
@"id": @(++jsonRpcId),
......@@ -135,7 +128,7 @@ static long jsonRpcId = 0;
{
NSAssert(method, @"No method specified");
if (!params) params = @[];
[self __rpcRequestWithObject:@{
//rpc 2.0
@"jsonrpc": @"2.0",
......
//
// JSONModelHTTPClient.m
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// JSONModel
//
#import "JSONHTTPClient.h"
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wdeprecated-implementations"
typedef void (^RequestResultBlock)(NSData *data, JSONModelError *error);
#pragma mark - constants
......@@ -97,7 +89,7 @@ static NSString* requestContentType = nil;
[requestString substringToIndex:1],
[requestString substringFromIndex: requestString.length -1]
];
if ([firstAndLastChar isEqualToString:@"{}"] || [firstAndLastChar isEqualToString:@"[]"]) {
//guessing for a JSON request
contentType = kContentTypeJSON;
......@@ -118,7 +110,7 @@ static NSString* requestContentType = nil;
if ([value isKindOfClass:[NSNumber class]]) {
value = [(NSNumber*)value stringValue];
}
NSAssert([value isKindOfClass:[NSString class]], @"request parameters can be only of NSString or NSNumber classes. '%@' is of class %@.", value, [value class]);
NSString *str = (NSString *)value;
......@@ -142,7 +134,7 @@ static NSString* requestContentType = nil;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url
cachePolicy: defaultCachePolicy
timeoutInterval: defaultTimeoutInSeconds];
[request setHTTPMethod:method];
[request setHTTPMethod:method];
if ([requestContentType isEqualToString:kContentTypeAutomatic]) {
//automatic content type
......@@ -154,17 +146,17 @@ static NSString* requestContentType = nil;
//user set content type
[request setValue: requestContentType forHTTPHeaderField:@"Content-type"];
}
//add all the custom headers defined
for (NSString* key in [requestHeaders allKeys]) {
[request setValue:requestHeaders[key] forHTTPHeaderField:key];
}
//add the custom headers
for (NSString* key in [headers allKeys]) {
[request setValue:headers[key] forHTTPHeaderField:key];
}
if (bodyData) {
[request setHTTPBody: bodyData];
[request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)bodyData.length] forHTTPHeaderField:@"Content-Length"];
......@@ -198,7 +190,7 @@ static NSString* requestContentType = nil;
if (!data.length) {
data = nil;
}
handler(data, error);
};
......@@ -231,7 +223,7 @@ static NSString* requestContentType = nil;
paramsString = [[NSMutableString alloc] initWithString: [paramsString substringToIndex: paramsString.length-1]];
}
}
//set the request params
if ([method isEqualToString:kHTTPMethodGET] && params) {
......@@ -242,7 +234,7 @@ static NSString* requestContentType = nil;
paramsString
]];
}
//call the more general synq request method
[self requestDataFromURL: url
method: method
......@@ -285,13 +277,13 @@ static NSString* requestContentType = nil;
//step 4: if there's a response at this and no errors, convert to object
if (error==nil) {
// Note: it is possible to have a valid response with empty response data (204 No Content).
// So only create the JSON object if there is some response data.
if(responseData.length > 0)
{
//convert to an object
jsonObject = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
}
// Note: it is possible to have a valid response with empty response data (204 No Content).
// So only create the JSON object if there is some response data.
if(responseData.length > 0)
{
//convert to an object
jsonObject = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
}
}
//step 4.5: cover an edge case in which meaningful content is return along an error HTTP status code
else if (error && responseData && jsonObject==nil) {
......@@ -300,7 +292,7 @@ static NSString* requestContentType = nil;
//keep responseData just in case it contains error information
error.responseData = responseData;
}
//step 5: invoke the complete block
dispatch_async(dispatch_get_main_queue(), ^{
if (completeBlock) {
......
//
// JSONModel+networking.h
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// JSONModel
//
#import "JSONModel.h"
#import "JSONHTTPClient.h"
typedef void (^JSONModelBlock)(id model, JSONModelError* err);
/**
* The JSONModel(networking) class category adds networking to JSONModel.
* It adds initFromURLWithString: initializer, which makes a GET http request
* to the URL given and initializes the model with the returned JSON.
* Use #import "JSONModel+networking.h" to import networking capabilities.
*/
@interface JSONModel(Networking)
@property (assign, nonatomic) BOOL isLoading;
/** @name Asynchronously create a model over the network */
/**
* Asynchronously create a model over the network. Create a new model instance and initialize it with the JSON fetched from the given URL
* @param urlString the absolute URL address of the JSON feed as a string
* @param completeBlock JSONModelBlock executed upon completion. The JSONModelBlock type is defined as: void (^JSONModelBlock)(JSONModel* model, JSONModelError* e); the first parameter is the initialized model or nil,
* and second parameter holds the model initialization error, if any
*/
-(instancetype)initFromURLWithString:(NSString *)urlString completion:(JSONModelBlock)completeBlock;
/**
* Asynchronously gets the contents of a URL and constructs a JSONModel object from the response.
* The constructed JSONModel object passed as the first parameter to the completion block will be of the same
* class as the receiver. So call this method on yourJSONModel sub-class rather than directly on JSONModel.
* @param urlString The absolute URL of the JSON resource, as a string
* @param completeBlock The block to be called upon completion.
* JSONModelBlock type is defined as: void (^JSONModelBlock)(JSONModel* model, JSONModelError* err);
* The first parameter is the initialized model (of the same JSONModel sub-class as the receiver) or nil if there was an error;
* The second parameter is the initialization error, if any.
*/
+ (void)getModelFromURLWithString:(NSString*)urlString completion:(JSONModelBlock)completeBlock;
typedef void (^JSONModelBlock)(id model, JSONModelError *err) DEPRECATED_ATTRIBUTE;
/**
* Asynchronously posts a JSONModel object (as JSON) to a URL and constructs a JSONModel object from the response.
* The constructed JSONModel object passed as the first parameter to the completion block will be of the same
* class as the receiver. So call this method on yourJSONModel sub-class rather than directly on JSONModel.
* @param post A JSONModel object that will be converted to JSON and sent as the POST data to the HTTP request.
* @param urlString The absolute URL of the JSON resource, as a string
* @param completeBlock The block to be called upon completion.
* JSONModelBlock type is defined as: void (^JSONModelBlock)(JSONModel* model, JSONModelError* err);
* The first parameter is the initialized model (of the same JSONModel sub-class as the receiver) or nil if there was an error;
* The second parameter is the initialization error, if any.
*/
+ (void)postModel:(JSONModel*)post toURLWithString:(NSString*)urlString completion:(JSONModelBlock)completeBlock;
@interface JSONModel (Networking)
@property (assign, nonatomic) BOOL isLoading DEPRECATED_ATTRIBUTE;
- (instancetype)initFromURLWithString:(NSString *)urlString completion:(JSONModelBlock)completeBlock DEPRECATED_ATTRIBUTE;
+ (void)getModelFromURLWithString:(NSString *)urlString completion:(JSONModelBlock)completeBlock DEPRECATED_ATTRIBUTE;
+ (void)postModel:(JSONModel *)post toURLWithString:(NSString *)urlString completion:(JSONModelBlock)completeBlock DEPRECATED_ATTRIBUTE;
@end
//
// JSONModel+networking.m
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// JSONModel
//
#import "JSONModel+networking.h"
#import "JSONHTTPClient.h"
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wdeprecated-implementations"
BOOL _isLoading;
@implementation JSONModel(Networking)
......@@ -37,25 +29,25 @@ BOOL _isLoading;
{
id placeholder = [super init];
__block id blockSelf = self;
if (placeholder) {
//initialization
self.isLoading = YES;
[JSONHTTPClient getJSONFromURLWithString:urlString
completion:^(NSDictionary *json, JSONModelError* e) {
JSONModelError* initError = nil;
blockSelf = [self initWithDictionary:json error:&initError];
if (completeBlock) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
completeBlock(blockSelf, e?e:initError );
});
}
self.isLoading = NO;
}];
}
return placeholder;
......@@ -63,47 +55,47 @@ BOOL _isLoading;
+ (void)getModelFromURLWithString:(NSString*)urlString completion:(JSONModelBlock)completeBlock
{
[JSONHTTPClient getJSONFromURLWithString:urlString
completion:^(NSDictionary* jsonDict, JSONModelError* err)
{
JSONModel* model = nil;
if(err == nil)
{
model = [[self alloc] initWithDictionary:jsonDict error:&err];
}
if(completeBlock != nil)
{
dispatch_async(dispatch_get_main_queue(), ^
{
completeBlock(model, err);
});
}
[JSONHTTPClient getJSONFromURLWithString:urlString
completion:^(NSDictionary* jsonDict, JSONModelError* err)
{
JSONModel* model = nil;
if(err == nil)
{
model = [[self alloc] initWithDictionary:jsonDict error:&err];
}
if(completeBlock != nil)
{
dispatch_async(dispatch_get_main_queue(), ^
{
completeBlock(model, err);
});
}
}];
}
+ (void)postModel:(JSONModel*)post toURLWithString:(NSString*)urlString completion:(JSONModelBlock)completeBlock
{
[JSONHTTPClient postJSONFromURLWithString:urlString
bodyString:[post toJSONString]
completion:^(NSDictionary* jsonDict, JSONModelError* err)
{
JSONModel* model = nil;
if(err == nil)
{
model = [[self alloc] initWithDictionary:jsonDict error:&err];
}
if(completeBlock != nil)
{
dispatch_async(dispatch_get_main_queue(), ^
{
completeBlock(model, err);
});
}
}];
[JSONHTTPClient postJSONFromURLWithString:urlString
bodyString:[post toJSONString]
completion:^(NSDictionary* jsonDict, JSONModelError* err)
{
JSONModel* model = nil;
if(err == nil)
{
model = [[self alloc] initWithDictionary:jsonDict error:&err];
}
if(completeBlock != nil)
{
dispatch_async(dispatch_get_main_queue(), ^
{
completeBlock(model, err);
});
}
}];
}
@end
//
// JSONKeyMapper.h
// JSONModel
//
// @version 1.2
// @author Marin Todorov (http://www.underplot.com) and contributors
//
// Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
// This code is distributed under the terms and conditions of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
typedef NSString* (^JSONModelKeyMapBlock)(NSString* keyName);
typedef NSString *(^JSONModelKeyMapBlock)(NSString *keyName);
/**
* **You won't need to create or store instances of this class yourself.** If you want your model
* to have different property names than the JSON feed keys, look below on how to
* to have different property names than the JSON feed keys, look below on how to
* make your model use a key mapper.
*
* For example if you consume JSON from twitter
......@@ -31,72 +20,72 @@ typedef NSString* (^JSONModelKeyMapBlock)(NSString* keyName);
*
* To comply with Obj-C accepted camelCase property naming for your classes,
* you need to provide mapping between JSON keys and ObjC property names.
*
* In your model overwrite the +(JSONKeyMapper*)keyMapper method and provide a JSONKeyMapper
*
* In your model overwrite the + (JSONKeyMapper *)keyMapper method and provide a JSONKeyMapper
* instance to convert the key names for your model.
*
*
* If you need custom mapping it's as easy as:
* <pre>
* +(JSONKeyMapper*)keyMapper {
* + (JSONKeyMapper *)keyMapper {
* &nbsp; return [[JSONKeyMapper&nbsp;alloc]&nbsp;initWithDictionary:@{@"crazy_JSON_name":@"myCamelCaseName"}];
* }
* </pre>
* In case you want to handle underscore_case, **use the predefined key mapper**, like so:
* <pre>
* +(JSONKeyMapper*)keyMapper {
* + (JSONKeyMapper *)keyMapper {
* &nbsp; return [JSONKeyMapper&nbsp;mapperFromUnderscoreCaseToCamelCase];
* }
* </pre>
*/
@interface JSONKeyMapper : NSObject
/** @name Name converters */
/** Block, which takes in a JSON key and converts it to the corresponding property name */
@property (readonly, nonatomic) JSONModelKeyMapBlock JSONToModelKeyBlock;
// deprecated
@property (readonly, nonatomic) JSONModelKeyMapBlock JSONToModelKeyBlock DEPRECATED_ATTRIBUTE;
- (NSString *)convertValue:(NSString *)value isImportingToModel:(BOOL)importing DEPRECATED_MSG_ATTRIBUTE("use convertValue:");
- (instancetype)initWithDictionary:(NSDictionary *)map DEPRECATED_MSG_ATTRIBUTE("use initWithModelToJSONDictionary:");
- (instancetype)initWithJSONToModelBlock:(JSONModelKeyMapBlock)toModel modelToJSONBlock:(JSONModelKeyMapBlock)toJSON DEPRECATED_MSG_ATTRIBUTE("use initWithModelToJSONBlock:");
+ (instancetype)mapper:(JSONKeyMapper *)baseKeyMapper withExceptions:(NSDictionary *)exceptions DEPRECATED_MSG_ATTRIBUTE("use baseMapper:withModelToJSONExceptions:");
+ (instancetype)mapperFromUnderscoreCaseToCamelCase DEPRECATED_MSG_ATTRIBUTE("use mapperForSnakeCase:");
+ (instancetype)mapperFromUpperCaseToLowerCase DEPRECATED_ATTRIBUTE;
/** @name Name converters */
/** Block, which takes in a property name and converts it to the corresponding JSON key name */
@property (readonly, nonatomic) JSONModelKeyMapBlock modelToJSONKeyBlock;
/** Combined converter method
* @param value the source name
* @param importing YES invokes JSONToModelKeyBlock, NO - modelToJSONKeyBlock
* @return JSONKeyMapper instance
*/
-(NSString*)convertValue:(NSString*)value isImportingToModel:(BOOL)importing;
* @param value the source name
* @return JSONKeyMapper instance
*/
- (NSString *)convertValue:(NSString *)value;
/** @name Creating a key mapper */
/**
* Creates a JSONKeyMapper instance, based on the two blocks you provide this initializer.
* The two parameters take in a JSONModelKeyMapBlock block:
* <pre>NSString* (^JSONModelKeyMapBlock)(NSString* keyName)</pre>
* Creates a JSONKeyMapper instance, based on the block you provide this initializer.
* The parameter takes in a JSONModelKeyMapBlock block:
* <pre>NSString *(^JSONModelKeyMapBlock)(NSString *keyName)</pre>
* The block takes in a string and returns the transformed (if at all) string.
* @param toModel transforms JSON key name to your model property name
* @param toJSON transforms your model property name to a JSON key
*/
-(instancetype)initWithJSONToModelBlock:(JSONModelKeyMapBlock)toModel
modelToJSONBlock:(JSONModelKeyMapBlock)toJSON;
- (instancetype)initWithModelToJSONBlock:(JSONModelKeyMapBlock)toJSON;
/**
* Creates a JSONKeyMapper instance, based on the mapping you provide
* in the map parameter. Use the JSON key names as keys, your JSONModel
* property names as values.
* @param map map dictionary, in the format: <pre>@{@"crazy_JSON_name":@"myCamelCaseName"}</pre>
* Creates a JSONKeyMapper instance, based on the mapping you provide.
* Use your JSONModel property names as keys, and the JSON key names as values.
* @param toJSON map dictionary, in the format: <pre>@{@"myCamelCaseName":@"crazy_JSON_name"}</pre>
* @return JSONKeyMapper instance
*/
-(instancetype)initWithDictionary:(NSDictionary*)map;
- (instancetype)initWithModelToJSONDictionary:(NSDictionary *)toJSON;
/**
* Creates a JSONKeyMapper, which converts underscore_case to camelCase and vice versa.
* Given a camelCase model property, this mapper finds JSON keys using the snake_case equivalent.
*/
+(instancetype)mapperFromUnderscoreCaseToCamelCase;
+(instancetype)mapperFromUpperCaseToLowerCase;
+ (instancetype)mapperForSnakeCase;
/**
* Creates a JSONKeyMapper based on a built-in JSONKeyMapper, with specific exceptions.
* Use the original JSON key names as keys, and your JSONModel property names as values.
* Use your JSONModel property names as keys, and the JSON key names as values.
*/
+ (instancetype)mapper:(JSONKeyMapper *)baseKeyMapper withExceptions:(NSDictionary *)exceptions;
+ (instancetype)baseMapper:(JSONKeyMapper *)baseKeyMapper withModelToJSONExceptions:(NSDictionary *)toJSON;
@end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Copyright (c) 2009-2015 Matej Bukovinski
Copyright © 2009-2016 Matej Bukovinski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment