diff --git a/WlianWorld.podspec b/WlianWorld.podspec index e288330..626b90a 100644 --- a/WlianWorld.podspec +++ b/WlianWorld.podspec @@ -91,23 +91,25 @@ Pod::Spec.new do |s| s.source_files = 'WlianWorld/Model/*','WlianWorld/Util/**/*','WlianWorld/View/*','WlianWorld/ViewModel/*','WlianWorld/Config/*' # s.exclude_files = "Classes/Exclude" - s.public_header_files = 'WlianWorld/Config/*.{h}','WlianWorld/Model/*.{h}','WlianWorld/Util/*.{h}' + s.prefix_header_file = 'WlianWorld/PrefixHeader.pch' s.frameworks = "UIKit" + s.dependency 'Mantle' s.dependency 'AFNetworking', '~> 2.5.4' s.dependency 'DTCoreText', '~>1.6.17' - s.dependency 'EGOCache', '~>2.13' + s.dependency 'EGOCache' s.dependency 'Godzippa', '~>1.1.0' s.dependency 'MBProgressHUD', '~>0.9.2' s.dependency 'MJRefresh', '~>3.1.0' s.dependency 'Reachability', '~>3.2' s.dependency 'ReactiveCocoa', '~>2.5' s.dependency 'SDWebImage', '~>3.7.4' - s.dependency 'SecureUDID', '~>1.1' + # s.dependency 'SecureUDID', '~>1.1' s.dependency 'STableViewController', '~>0.0.1' s.dependency 'SVWebViewController', '~>1.0' s.dependency 'SBJson', '~>4.0.2' + # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # # # A list of resources included with the Pod. These are copied into the diff --git a/WlianWorld.xcworkspace/xcuserdata/xmfish.xcuserdatad/UserInterfaceState.xcuserstate b/WlianWorld.xcworkspace/xcuserdata/xmfish.xcuserdatad/UserInterfaceState.xcuserstate index 30d9552..e6b4155 100644 Binary files a/WlianWorld.xcworkspace/xcuserdata/xmfish.xcuserdatad/UserInterfaceState.xcuserstate and b/WlianWorld.xcworkspace/xcuserdata/xmfish.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/WlianWorld.xcworkspace/xcuserdata/xmfish.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/WlianWorld.xcworkspace/xcuserdata/xmfish.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 74da02c..69fac59 100644 --- a/WlianWorld.xcworkspace/xcuserdata/xmfish.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/WlianWorld.xcworkspace/xcuserdata/xmfish.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,54 +3,6 @@ type = "0" version = "2.0"> - - - - - - - - - - - - +@interface BaseModel : MTLModel -@interface BaseModel : MTLModel - -@property (nonatomic,strong)NSString* title; -@property (nonatomic,readonly)NSString* errorCode; -@property (nonatomic,readonly)NSString* errorMessage; +@property (nonatomic, strong) NSString* title; +@property (nonatomic, readonly) NSString* errorCode; +@property (nonatomic, readonly) NSString* errorMessage; @end diff --git a/WlianWorld/Model/BaseModel.m b/WlianWorld/Model/BaseModel.m index c2b8e90..090493c 100644 --- a/WlianWorld/Model/BaseModel.m +++ b/WlianWorld/Model/BaseModel.m @@ -7,40 +7,41 @@ // #import "BaseModel.h" - @implementation BaseModel -+ (NSDictionary *)JSONKeyPathsByPropertyKey { ++ (NSDictionary*)JSONKeyPathsByPropertyKey +{ return @{ - // @"errCode": @"ret", - @"errorCode": @"errorCode", - @"errorMessage": @"errorMessage", - }; + // @"errCode": @"ret", + @"errorCode" : @"errorCode", + @"errorMessage" : @"errorMessage", + }; } -+ (NSValueTransformer *)errorCodeJSONTransformer { - return [MTLValueTransformer transformerUsingForwardBlock:^id(id value,BOOL *success, NSError *__autoreleasing *error) { - - NSNumber *num = value; - - NSString *tempStr = [NSString stringWithFormat:@"%@", num]; - ++ (NSValueTransformer*)errorCodeJSONTransformer +{ + return [MTLValueTransformer transformerUsingForwardBlock:^id(id value, BOOL* success, NSError* __autoreleasing* error) { + + NSNumber* num = value; + + NSString* tempStr = [NSString stringWithFormat:@"%@", num]; + return tempStr; - - } reverseBlock:^id(id value,BOOL *success, NSError *__autoreleasing *error) { - - NSString *tempStr = value; - - NSNumber *tempNum = @(tempStr.integerValue); - - return tempNum; - - }]; + + } + reverseBlock:^id(id value, BOOL* success, NSError* __autoreleasing* error) { + + NSString* tempStr = value; + + NSNumber* tempNum = @(tempStr.integerValue); + + return tempNum; + + }]; } -- (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error +- (instancetype)initWithDictionary:(NSDictionary*)dictionaryValue error:(NSError**)error { self = [super initWithDictionary:dictionaryValue error:error]; - if (self != nil) - { + if (self != nil) { } return self; } diff --git a/WlianWorld/Model/BaseWLService.m b/WlianWorld/Model/BaseWLService.m index a2cb3c2..84820fb 100644 --- a/WlianWorld/Model/BaseWLService.m +++ b/WlianWorld/Model/BaseWLService.m @@ -6,95 +6,86 @@ // Copyright © 2015年 ash. All rights reserved. // -#import "BaseWLService.h" - #import "BaseEntity.h" +#import "BaseWLService.h" +#import "Common.h" -#import "MTLJSONAdapter.h" #import "NSData+Godzippa.h" -#import "EGOCache.h" #import "BaseAPIClient.h" +#import @implementation BaseWLService -+ (void)saveCacheWithAPIKey:(NSString *)apiKey property:(BaseEntity *)proper data:(id)tweet{ ++ (void)saveCacheWithAPIKey:(NSString*)apiKey property:(BaseEntity*)proper data:(id)tweet +{ if (proper.isCache) { SEL selector = NSSelectorFromString(@"errCode"); IMP imp = [tweet methodForSelector:selector]; - NSString* (*func)(id, SEL) = (void *)imp; - NSString *tmpErrCode = func(tweet, selector); + NSString* (*func)(id, SEL) = (void*)imp; + NSString* tmpErrCode = func(tweet, selector); DLog(@"%@", tmpErrCode); - - if (([tmpErrCode isKindOfClass:[NSString class]] && [tmpErrCode isEqualToString:@"0"] ) || ([tmpErrCode isKindOfClass:[NSNumber class]] && [tmpErrCode integerValue]==0)) { + + if (([tmpErrCode isKindOfClass:[NSString class]] && [tmpErrCode isEqualToString:@"0"]) || ([tmpErrCode isKindOfClass:[NSNumber class]] && [tmpErrCode integerValue] == 0)) { [[EGOCache globalCache] setObject:tweet forKey:apiKey]; - } } } -+ (void)responseFromCacheWithAPIKey:(NSString *)apiKey property:(BaseEntity *)proper completionBlock:(id)subscriber{ ++ (void)responseFromCacheWithAPIKey:(NSString*)apiKey property:(BaseEntity*)proper completionBlock:(id)subscriber +{ if (proper.isCache && [[EGOCache globalCache] hasCacheForKey:apiKey]) { [subscriber sendNext:[[EGOCache globalCache] objectForKey:apiKey]]; [subscriber sendCompleted]; } } -+(RACSignal*)requireWithProperty:(BaseEntity *)proper ++ (RACSignal*)requireWithProperty:(BaseEntity*)proper { - -// if (proper.requireType == HTTPRequestTypeWithGET) { -// return [self requireWithGetWithProperty:proper]; -// } -// return nil; + + // if (proper.requireType == HTTPRequestTypeWithGET) { + // return [self requireWithGetWithProperty:proper]; + // } + // return nil; return [self requireWithGetWithProperty:proper]; } -+(RACSignal*)requireWithGetWithProperty:(BaseEntity*)proper ++ (RACSignal*)requireWithGetWithProperty:(BaseEntity*)proper { - NSString *apiKey = proper.cacheKey; - if (proper.pro && proper.pro[@"page"]) - { - apiKey = [apiKey stringByAppendingFormat:@"%@",proper.pro[@"page"]]; + NSString* apiKey = proper.cacheKey; + if (proper.pro && proper.pro[@"page"]) { + apiKey = [apiKey stringByAppendingFormat:@"%@", proper.pro[@"page"]]; } - - - return [[RACSignal createSignal:^RACDisposable *(id subscriber) { + return [[RACSignal createSignal:^RACDisposable*(id subscriber) { [[BaseAPIClient sharedClient] GET:[proper reqURL] - parameters: [proper encodePro] - success:^(AFHTTPRequestOperation * __unused task, id json) { - DLog(@"%@", json); - - if(json) - { - NSError *error = nil; - id tweet = [MTLJSONAdapter modelOfClass:[proper.responesOBJ class] fromJSONDictionary:json error:&error]; - - - [subscriber sendNext:tweet]; - [subscriber sendCompleted]; - - [self saveCacheWithAPIKey:apiKey property:proper data:tweet]; - - } - else - { - [subscriber sendNext:nil]; - [subscriber sendCompleted]; - } - } - failure:^(AFHTTPRequestOperation *__unused task, NSError *error) { - DLog(@"%@", error.description); - - [subscriber sendError:error]; - - [self responseFromCacheWithAPIKey:apiKey property:proper completionBlock:subscriber]; - }]; - + parameters:[proper encodePro] + success:^(AFHTTPRequestOperation* __unused task, id json) { + DLog(@"%@", json); + + if (json) { + NSError* error = nil; + id tweet = [MTLJSONAdapter modelOfClass:[proper.responesOBJ class] fromJSONDictionary:json error:&error]; + + [subscriber sendNext:tweet]; + [subscriber sendCompleted]; + + [self saveCacheWithAPIKey:apiKey property:proper data:tweet]; + } + else { + [subscriber sendNext:nil]; + [subscriber sendCompleted]; + } + } + failure:^(AFHTTPRequestOperation* __unused task, NSError* error) { + DLog(@"%@", error.description); + + [subscriber sendError:error]; + + [self responseFromCacheWithAPIKey:apiKey property:proper completionBlock:subscriber]; + }]; + return [RACDisposable disposableWithBlock:^{ }]; - - }] replayLazily]; - + }] replayLazily]; } @end diff --git a/WlianWorld/Model/LoginModel.m b/WlianWorld/Model/LoginModel.m index 1ae59a9..1e82b2b 100644 --- a/WlianWorld/Model/LoginModel.m +++ b/WlianWorld/Model/LoginModel.m @@ -6,6 +6,8 @@ // Copyright © 2015年 ash. All rights reserved. // +#import "BaseEntity.h" +#import "BaseWLService.h" #import "LoginModel.h" #import "LoginViewModel.h" @implementation LoginModel diff --git a/WlianWorld/Model/NSString+HXAddtions.m b/WlianWorld/Model/NSString+HXAddtions.m index 7335799..3f98c66 100644 --- a/WlianWorld/Model/NSString+HXAddtions.m +++ b/WlianWorld/Model/NSString+HXAddtions.m @@ -10,98 +10,86 @@ #import @implementation NSString (HXAddtions) -+(NSString *) jsonStringWithString:(NSString *) string ++ (NSString*)jsonStringWithString:(NSString*)string { return [NSString stringWithFormat:@"\"%@\"", - [[string stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"] stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""] - ]; + [[string stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"] stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]; } -+(NSString *) jsonStringWithArray:(NSArray *)array ++ (NSString*)jsonStringWithArray:(NSArray*)array { - NSMutableString *reString = [NSMutableString string]; + NSMutableString* reString = [NSMutableString string]; [reString appendString:@"["]; - NSMutableArray *values = [NSMutableArray array]; + NSMutableArray* values = [NSMutableArray array]; for (id valueObj in array) { - NSString *value = [NSString jsonStringWithObject:valueObj]; + NSString* value = [NSString jsonStringWithObject:valueObj]; if (value) { - [values addObject:[NSString stringWithFormat:@"%@",value]]; + [values addObject:[NSString stringWithFormat:@"%@", value]]; } } - [reString appendFormat:@"%@",[values componentsJoinedByString:@","]]; - [reString appendString:@"]"]; + [reString appendFormat:@"%@", [values componentsJoinedByString:@","]]; + [reString appendString:@"]"]; return reString; } -+(NSString *) jsonStringWithDictionary:(NSDictionary *)dictionary ++ (NSString*)jsonStringWithDictionary:(NSDictionary*)dictionary { - NSArray *keys = [dictionary allKeys]; - NSMutableString *reString = [NSMutableString string]; + NSArray* keys = [dictionary allKeys]; + NSMutableString* reString = [NSMutableString string]; [reString appendString:@"{"]; - NSMutableArray *keyValues = [NSMutableArray array]; - for (int i=0; i<[keys count]; i++) { - NSString *name = [keys objectAtIndex:i]; + NSMutableArray* keyValues = [NSMutableArray array]; + for (int i = 0; i < [keys count]; i++) { + NSString* name = [keys objectAtIndex:i]; id valueObj = [dictionary objectForKey:name]; - NSString *value = [NSString jsonStringWithObject:valueObj]; - if (value) - { - [keyValues addObject:[NSString stringWithFormat:@"\"%@\":%@",name,value]]; + NSString* value = [NSString jsonStringWithObject:valueObj]; + if (value) { + [keyValues addObject:[NSString stringWithFormat:@"\"%@\":%@", name, value]]; } } - [reString appendFormat:@"%@",[keyValues componentsJoinedByString:@","]]; + [reString appendFormat:@"%@", [keyValues componentsJoinedByString:@","]]; [reString appendString:@"}"]; return reString; } -+(NSString *) jsonStringWithObject:(id) object ++ (NSString*)jsonStringWithObject:(id)object { - NSString *value = nil; - if (!object) - { + NSString* value = nil; + if (!object) { return value; } - - if ([object isKindOfClass:[NSString class]]) - { + + if ([object isKindOfClass:[NSString class]]) { value = [NSString jsonStringWithString:object]; } - else if([object isKindOfClass:[NSDictionary class]]) - { + else if ([object isKindOfClass:[NSDictionary class]]) { value = [NSString jsonStringWithDictionary:object]; } - else if([object isKindOfClass:[NSArray class]]) - { + else if ([object isKindOfClass:[NSArray class]]) { value = [NSString jsonStringWithArray:object]; } - else if([object isKindOfClass:[NSNumber class]]) - { + else if ([object isKindOfClass:[NSNumber class]]) { value = [NSString jsonStringWithString:[object stringValue]]; } return value; } -+(NSString *) jsonStringWithRTArray:(NSArray *)array ++ (NSString*)jsonStringWithRTArray:(NSArray*)array { - NSMutableString *reString = [[NSMutableString alloc] init]; + NSMutableString* reString = [[NSMutableString alloc] init]; [reString appendString:@"{"]; - NSMutableArray *values = [[NSMutableArray alloc] initWithArray:array]; - for (int i=0; i<[values count]; i++) - { - NSString *tempString = [values objectAtIndex:i]; - NSString *value = [NSString jsonStringWithString:tempString]; - if (i%2 == 0) - { - [reString appendFormat:@"%@:",value]; + NSMutableArray* values = [[NSMutableArray alloc] initWithArray:array]; + for (int i = 0; i < [values count]; i++) { + NSString* tempString = [values objectAtIndex:i]; + NSString* value = [NSString jsonStringWithString:tempString]; + if (i % 2 == 0) { + [reString appendFormat:@"%@:", value]; } - else - { - if (i == [values count]-1) - { - [reString appendFormat:@"%@",value]; + else { + if (i == [values count] - 1) { + [reString appendFormat:@"%@", value]; } - else - { - [reString appendFormat:@"%@,",value]; + else { + [reString appendFormat:@"%@,", value]; } } } @@ -109,17 +97,16 @@ return reString; } -- (NSString *) md5 +- (NSString*)md5 { - const char *cStr = [self UTF8String]; + const char* cStr = [self UTF8String]; unsigned char result[16]; - CC_MD5( cStr, strlen(cStr), result ); // This is the md5 call + CC_MD5(cStr, (int)strlen(cStr), result); // This is the md5 call return [NSString stringWithFormat: - @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - result[0], result[1], result[2], result[3], - result[4], result[5], result[6], result[7], - result[8], result[9], result[10], result[11], - result[12], result[13], result[14], result[15] - ]; + @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + result[0], result[1], result[2], result[3], + result[4], result[5], result[6], result[7], + result[8], result[9], result[10], result[11], + result[12], result[13], result[14], result[15]]; } @end \ No newline at end of file diff --git a/WlianWorld/PrefixHeader.pch b/WlianWorld/PrefixHeader.pch index 09e8eb7..97b223a 100644 --- a/WlianWorld/PrefixHeader.pch +++ b/WlianWorld/PrefixHeader.pch @@ -11,12 +11,10 @@ // Include any system framework and library headers here that should be included in all compilation units. // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. -#import -#import -#import -#import "Common.h" -#import "BaseEntity.h" -#import "BaseWLService.h" -#import -#import "MBProgressHUD+Util.h" + +//#import "Common.h" +//#import "BaseEntity.h" +//#import "BaseWLService.h" +//#import "MBProgressHUD+Util.h" +#import #endif /* PrefixHeader_pch */ diff --git a/WlianWorld/View/LoginViewController.m b/WlianWorld/View/LoginViewController.m index 5960557..3887aa0 100644 --- a/WlianWorld/View/LoginViewController.m +++ b/WlianWorld/View/LoginViewController.m @@ -7,8 +7,10 @@ // #import "AWordDefault.h" +#import "Common.h" #import "LoginViewController.h" #import "LoginViewModel.h" +#import "MBProgressHUD+Util.h" @interface LoginViewController () @property (weak, nonatomic) IBOutlet UIButton* sureBtn; diff --git a/WlianWorld/ViewModel/BaseViewModel.m b/WlianWorld/ViewModel/BaseViewModel.m index 2fc1590..baed5fe 100644 --- a/WlianWorld/ViewModel/BaseViewModel.m +++ b/WlianWorld/ViewModel/BaseViewModel.m @@ -6,15 +6,16 @@ // Copyright © 2015年 ash. All rights reserved. // -#import "BaseViewModel.h" +#import "BaseEntity.h" #import "BaseModel.h" +#import "BaseViewModel.h" @implementation BaseViewModel -+(BaseEntity*)requireWithDic:(NSDictionary *)dic withModel:(BaseModel*)model ++ (BaseEntity*)requireWithDic:(NSDictionary*)dic withModel:(BaseModel*)model { - BaseEntity *pro = [[BaseEntity alloc] init]; + BaseEntity* pro = [[BaseEntity alloc] init]; pro.requireType = HTTPRequestTypeWithGET; - pro.responesOBJ = model.class; + pro.responesOBJ = [(id)model class]; pro.reqURL = @""; pro.pro = dic; return pro;