-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
118 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
// | ||
|
||
#import "YBBaseRequest.h" | ||
#import "YBNetworkResponse+YBCustom.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
YBNetworkDemo/TestCase/为响应对象拓展属性/YBNetworkResponse+YBCustom.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// YBNetworkResponse+YBCustom.h | ||
// YBNetworkDemo | ||
// | ||
// Created by 波儿菜 on 2019/9/27. | ||
// Copyright © 2019 杨波. All rights reserved. | ||
// | ||
|
||
#import "YBNetworkResponse.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/// 网络响应错误类型 | ||
typedef NS_ENUM(NSInteger, YBResponseErrorType) { | ||
/// 未知 | ||
YBResponseErrorTypeUnknown, | ||
/// 超时 | ||
YBResponseErrorTypeTimedOut, | ||
/// 取消 | ||
YBResponseErrorTypeCancelled, | ||
/// 无网络 | ||
YBResponseErrorTypeNoNetwork, | ||
/// 服务器错误 | ||
YBResponseErrorTypeServerError, | ||
/// 登录状态过期 | ||
YBResponseErrorTypeLoginExpired | ||
}; | ||
|
||
@interface YBNetworkResponse (YBCustom) | ||
|
||
/// 请求失败类型 (使用该属性做业务处理足够) | ||
@property (nonatomic, assign) YBResponseErrorType errorType; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
23 changes: 23 additions & 0 deletions
23
YBNetworkDemo/TestCase/为响应对象拓展属性/YBNetworkResponse+YBCustom.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// YBNetworkResponse+YBCustom.m | ||
// YBNetworkDemo | ||
// | ||
// Created by 波儿菜 on 2019/9/27. | ||
// Copyright © 2019 杨波. All rights reserved. | ||
// | ||
|
||
#import "YBNetworkResponse+YBCustom.h" | ||
#import <objc/runtime.h> | ||
|
||
@implementation YBNetworkResponse (YBCustom) | ||
|
||
static void const *YBNetworkResponseErrorTypeKey = &YBNetworkResponseErrorTypeKey; | ||
- (void)setErrorType:(YBResponseErrorType)errorType { | ||
objc_setAssociatedObject(self, YBNetworkResponseErrorTypeKey, @(errorType), OBJC_ASSOCIATION_RETAIN_NONATOMIC); | ||
} | ||
- (YBResponseErrorType)errorType { | ||
NSNumber *tmp = objc_getAssociatedObject(self, YBNetworkResponseErrorTypeKey); | ||
return tmp.integerValue; | ||
} | ||
|
||
@end |