diff --git a/Demos/GooglePlacesDemo/GooglePlacesDemo.xcodeproj/project.pbxproj b/Demos/GooglePlacesDemo/GooglePlacesDemo.xcodeproj/project.pbxproj index ad8034e..c4807b4 100644 --- a/Demos/GooglePlacesDemo/GooglePlacesDemo.xcodeproj/project.pbxproj +++ b/Demos/GooglePlacesDemo/GooglePlacesDemo.xcodeproj/project.pbxproj @@ -35,11 +35,11 @@ 40E75FBE1796E90100AEC295 /* GooglePlacesWebservice.m in Sources */ = {isa = PBXBuildFile; fileRef = 40E75FBD1796E90100AEC295 /* GooglePlacesWebservice.m */; }; 40E75FC01796EBC500AEC295 /* SearchIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 40E75FBF1796EBC500AEC295 /* SearchIcon.png */; }; 40E75FC41796EFDC00AEC295 /* MapPin.png in Resources */ = {isa = PBXBuildFile; fileRef = 40E75FC21796EFDC00AEC295 /* MapPin.png */; }; - 40E75FC71796F10300AEC295 /* NSObject+ObjectMap.m in Sources */ = {isa = PBXBuildFile; fileRef = 40E75FC61796F10300AEC295 /* NSObject+ObjectMap.m */; }; 40E75FCA1796F26500AEC295 /* MapAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 40E75FC91796F26500AEC295 /* MapAnnotation.m */; }; 40E75FCC17970BCE00AEC295 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 40E75FCB17970BCE00AEC295 /* MapKit.framework */; }; 40E75FCE17970D7D00AEC295 /* MapPin@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 40E75FCD17970D7D00AEC295 /* MapPin@2x.png */; }; 40E75FD7179710C100AEC295 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 40E75FD6179710C100AEC295 /* CoreLocation.framework */; }; + B6F7E06A18C61F9500EBD65F /* NSObject+ObjectMap.m in Sources */ = {isa = PBXBuildFile; fileRef = B6F7E06918C61F9500EBD65F /* NSObject+ObjectMap.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -91,13 +91,13 @@ 40E75FBD1796E90100AEC295 /* GooglePlacesWebservice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GooglePlacesWebservice.m; sourceTree = ""; }; 40E75FBF1796EBC500AEC295 /* SearchIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = SearchIcon.png; sourceTree = ""; }; 40E75FC21796EFDC00AEC295 /* MapPin.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = MapPin.png; sourceTree = ""; }; - 40E75FC51796F10300AEC295 /* NSObject+ObjectMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+ObjectMap.h"; sourceTree = ""; }; - 40E75FC61796F10300AEC295 /* NSObject+ObjectMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+ObjectMap.m"; sourceTree = ""; }; 40E75FC81796F26500AEC295 /* MapAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapAnnotation.h; sourceTree = ""; }; 40E75FC91796F26500AEC295 /* MapAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapAnnotation.m; sourceTree = ""; }; 40E75FCB17970BCE00AEC295 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; 40E75FCD17970D7D00AEC295 /* MapPin@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "MapPin@2x.png"; sourceTree = ""; }; 40E75FD6179710C100AEC295 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; + B6F7E06818C61F9500EBD65F /* NSObject+ObjectMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSObject+ObjectMap.h"; path = "../../../NSObject-ObjectMap/NSObject+ObjectMap.h"; sourceTree = ""; }; + B6F7E06918C61F9500EBD65F /* NSObject+ObjectMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSObject+ObjectMap.m"; path = "../../../NSObject-ObjectMap/NSObject+ObjectMap.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -148,8 +148,8 @@ 40E75F731796E88E00AEC295 /* GooglePlacesDemo */ = { isa = PBXGroup; children = ( - 40E75FC51796F10300AEC295 /* NSObject+ObjectMap.h */, - 40E75FC61796F10300AEC295 /* NSObject+ObjectMap.m */, + B6F7E06818C61F9500EBD65F /* NSObject+ObjectMap.h */, + B6F7E06918C61F9500EBD65F /* NSObject+ObjectMap.m */, 40E75F931796E8C500AEC295 /* Google Places */, 40E75F7C1796E88E00AEC295 /* AppDelegate.h */, 40E75F7D1796E88E00AEC295 /* AppDelegate.m */, @@ -309,9 +309,9 @@ 40E75FB81796E8F400AEC295 /* GooglePlaceDetails.m in Sources */, 40E75FB91796E8F400AEC295 /* GoogleAddressComponent.m in Sources */, 40E75FBA1796E8F400AEC295 /* GoogleReview.m in Sources */, + B6F7E06A18C61F9500EBD65F /* NSObject+ObjectMap.m in Sources */, 40E75FBB1796E8F400AEC295 /* GoogleReviewAspect.m in Sources */, 40E75FBE1796E90100AEC295 /* GooglePlacesWebservice.m in Sources */, - 40E75FC71796F10300AEC295 /* NSObject+ObjectMap.m in Sources */, 40E75FCA1796F26500AEC295 /* MapAnnotation.m in Sources */, 11CD5EB317AA96BF00CF3BDD /* GPOperation.m in Sources */, ); diff --git a/Demos/GooglePlacesDemo/GooglePlacesDemo/NSObject+ObjectMap.h b/Demos/GooglePlacesDemo/GooglePlacesDemo/NSObject+ObjectMap.h deleted file mode 100644 index 1697532..0000000 --- a/Demos/GooglePlacesDemo/GooglePlacesDemo/NSObject+ObjectMap.h +++ /dev/null @@ -1,55 +0,0 @@ -// -// NSObject+JSONMap.h -// TenEight -// -// Created by Benjamin Gordon on 5/8/13. -// Copyright (c) 2013 Matthew York. All rights reserved. -// - -#import -#import - -#define OMDateFormat @"yyyy-MM-dd'T'HH:mm:ss.SSS" -#define OMTimeZone @"UTC" - -@interface NSObject (ObjectMap) - -// Universal Method --(NSDictionary *)propertyDictionary; --(NSString *)nameOfClass; - -// id -> Object -+(id)objectOfClass:(NSString *)object fromJSON:(NSDictionary *)dict; -+(NSArray *)arrayFromJSON:(NSArray *)jsonArray ofObjects:(NSString *)obj; - -//Object -> Data --(NSDictionary *)objectDictionary; --(NSData *)JSONData; --(NSString *)JSONString; - -// XML-SOAP --(NSData *)XMLData; --(NSString *)XMLString; --(NSData *)SOAPData; --(NSString *)SOAPString; -+(id)objectOfClass:(NSString *)object fromXML:(NSString *)xml; - - -// For mapping an array to properties --(NSMutableDictionary *)getPropertyArrayMap; - - -// Copying an NSObject to new memory ref -// (basically initWithObject) --(id)initWithObject:(NSObject *)oldObject error:(NSError **)error; - -// Base64 Encode/Decode -+(NSString *)encodeBase64WithData:(NSData *)objData; -+(NSData *)base64DataFromString:(NSString *)string; - -@end - -@interface SOAPObject : NSObject -@property (nonatomic, retain) id Header; -@property (nonatomic, retain) id Body; -@end \ No newline at end of file diff --git a/Demos/GooglePlacesDemo/GooglePlacesDemo/NSObject+ObjectMap.m b/Demos/GooglePlacesDemo/GooglePlacesDemo/NSObject+ObjectMap.m deleted file mode 100644 index bacabe9..0000000 --- a/Demos/GooglePlacesDemo/GooglePlacesDemo/NSObject+ObjectMap.m +++ /dev/null @@ -1,915 +0,0 @@ -// -// NSObject+JSONMap.m -// TenEight -// -// Created by Benjamin Gordon on 5/8/13. -// Copyright (c) 2013 Matthew York. All rights reserved. -// - -#import "NSObject+ObjectMap.h" - -static const char _base64EncodingTable[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const short _base64DecodingTable[256] = { - -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -1, -1, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -2, -2, -2, - -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, -2, - -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 -}; - - -@implementation NSObject (ObjectMap) - -#pragma mark - XML to Object -+(id)objectOfClass:(NSString *)object fromXML:(NSString *)xml { - id newObject = [[NSClassFromString(object) alloc] init]; - - NSDictionary *mapDictionary = [newObject propertyDictionary]; - - for (NSString *key in [mapDictionary allKeys]) { - objc_property_t property = class_getProperty([newObject class], [key UTF8String]); - NSString *className = [[newObject typeFromProperty:property] substringWithRange:NSMakeRange(3, [newObject typeFromProperty:property].length - 4)]; - id objForKey; - - // Check Types - if ([className isEqualToString:@"NSString"]) { - objForKey = [[NSString alloc] init]; - } - else if ([className isEqualToString:@"NSDate"]) { - objForKey = [NSDate date]; - } - else if ([className isEqualToString:@"NSNumber"]) { - objForKey = [[NSNumber alloc] initWithFloat:0.00]; - } - else if ([className isEqualToString:@"NSArray"]) { - objForKey = [[NSArray alloc] init]; - } - else if ([className isEqualToString:@"NSData"]){ - objForKey = [[NSData alloc] init]; - } - else { - objForKey = [[NSClassFromString(className) alloc] init]; - } - - // Create - [newObject setValue:[objForKey getNodeValue:key fromXML:xml] forKey:key]; - } - - return newObject; -} - --(id)getNodeValue:(NSString *)node fromXML:(NSString *)xml { - NSString *trash = @""; - NSString *value = @""; - NSScanner *xmlScanner = [NSScanner scannerWithString:xml]; - [xmlScanner scanUpToString:[NSString stringWithFormat:@"<%@", node] intoString:&trash]; - [xmlScanner scanUpToString:@">" intoString:&trash]; - [xmlScanner scanString:@">" intoString:&trash]; - - // Check property type - if ([self isKindOfClass:[NSArray class]]) { - // Set up a new scanner for xml substring - [xmlScanner scanUpToString:[NSString stringWithFormat:@"" intoString:&filteredArrayObj]; - NSScanner *insideArrayScanner = [NSScanner scannerWithString:value]; - NSString *newValue = @""; - NSMutableArray *objArray = [@[] mutableCopy]; - - // Scan and create objects until you can't no mo' - while (![insideArrayScanner isAtEnd]) { - [insideArrayScanner scanUpToString:[NSString stringWithFormat:@"<%@", filteredArrayObj] intoString:&trash]; - [insideArrayScanner scanUpToString:@">" intoString:&trash]; - [insideArrayScanner scanString:@">" intoString:&trash]; - [insideArrayScanner scanUpToString:[NSString stringWithFormat:@"" intoString:&trash]; - [insideArrayScanner scanString:@">" intoString:&trash]; - } - - // Return the array - return objArray; - } - - else if ([self isKindOfClass:[NSNumber class]]) { - [xmlScanner scanUpToString:@" make into object/id - else if ([[dict objectForKey:key] isKindOfClass:[NSArray class]]) { - NSArray *nestedArray = [dict objectForKey:key]; - NSString *propertyType = [newObject valueForKeyPath:[NSString stringWithFormat:@"propertyArrayMap.%@", key]]; - [newObject setValue:[NSObject arrayMapFromArray:nestedArray forPropertyName:propertyType] forKey:propertyName]; - } - - // Add to property name, because it is a type already - else { - objc_property_t property = class_getProperty([newObject class], [propertyName UTF8String]); - NSString *classType = [newObject typeFromProperty:property]; - - // check if NSDate or not - if ([classType isEqualToString:@"T@\"NSDate\""]) { - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:OMDateFormat]; - [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]]; - NSString *dateString = [[dict objectForKey:key] stringByReplacingOccurrencesOfString:@"T" withString:@" "]; - [newObject setValue:[formatter dateFromString:dateString] forKey:propertyName]; - } - else { - if ([dict objectForKey:key] != [NSNull null]) { - [newObject setValue:[dict objectForKey:key] forKey:propertyName]; - } - else { - [newObject setValue:nil forKey:propertyName]; - } - } - } - } - - return newObject; -} - --(NSString *)classOfPropertyNamed:(NSString *)propName { - unsigned count; - objc_property_t *properties = class_copyPropertyList([self class], &count); - - for (int xx = 0; xx < count; xx++) { - if ([[NSString stringWithUTF8String:property_getName(properties[xx])] isEqualToString:propName]) { - NSString *className = [NSString stringWithFormat:@"%s", getPropertyType(properties[xx])]; - free(properties); - return className; - } - } - - return nil; -} - - -static const char * getPropertyType(objc_property_t property) { - const char *attributes = property_getAttributes(property); - printf("attributes=%s\n", attributes); - char buffer[1 + strlen(attributes)]; - strcpy(buffer, attributes); - char *state = buffer, *attribute; - while ((attribute = strsep(&state, ",")) != NULL) { - if (attribute[0] == 'T' && attribute[1] != '@') { - // it's a C primitive type: - /* - if you want a list of what will be returned for these primitives, search online for - "objective-c" "Property Attribute Description Examples" - apple docs list plenty of examples of what you get for int "i", long "l", unsigned "I", struct, etc. - */ - return (const char *)[[NSData dataWithBytes:(attribute + 1) length:strlen(attribute) - 1] bytes]; - } - else if (attribute[0] == 'T' && attribute[1] == '@' && strlen(attribute) == 2) { - // it's an ObjC id type: - return "id"; - } - else if (attribute[0] == 'T' && attribute[1] == '@') { - // it's another ObjC object type: - return (const char *)[[NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4] bytes]; - } - } - return ""; -} - -+(NSArray *)arrayFromJSON:(NSArray *)jsonArray ofObjects:(NSString *)obj { - //NSString *filteredObject = [NSString stringWithFormat:@"%@s",obj]; - return [NSObject arrayMapFromArray:jsonArray forPropertyName:obj]; -} - --(NSString *)nameOfClass { - return [NSString stringWithUTF8String:class_getName([self class])]; -} - -+(NSArray *)arrayMapFromArray:(NSArray *)nestedArray forPropertyName:(NSString *)propertyName { - // Set Up - NSMutableArray *objectsArray = [@[] mutableCopy]; - - // Removes "ArrayOf(PropertyName)s" to get to the meat - //NSString *filteredProperty = [propertyName substringWithRange:NSMakeRange(0, propertyName.length - 1)]; /* TenEight */ - //NSString *filteredProperty = [propertyName substringWithRange:NSMakeRange(7, propertyName.length - 8)]; /* AlaCop */ - - // Create objects - for (int xx = 0; xx < nestedArray.count; xx++) { - // If it's an NSDictionary - if ([nestedArray[xx] isKindOfClass:[NSDictionary class]]) { - // Create object of filteredProperty type - id nestedObj = [[NSClassFromString(propertyName) alloc] init]; - - // Iterate through each key, create objects for each - for (NSString *newKey in [nestedArray[xx] allKeys]) { - // If it's an Array, recur - if ([[nestedArray[xx] objectForKey:newKey] isKindOfClass:[NSArray class]]) { - NSString *propertyType = [nestedObj valueForKeyPath:[NSString stringWithFormat:@"propertyArrayMap.%@", newKey]]; - [nestedObj setValue:[NSObject arrayMapFromArray:[nestedArray[xx] objectForKey:newKey] forPropertyName:propertyType] forKey:newKey]; - } - // If it's a Dictionary, create an object, and send to [self objectFromJSON] - else if ([[nestedArray[xx] objectForKey:newKey] isKindOfClass:[NSDictionary class]]) { - NSString *type = [nestedObj classOfPropertyNamed:newKey]; - - id nestedDictObj = [NSObject objectOfClass:type fromJSON:[nestedArray[xx] objectForKey:newKey]]; - [nestedObj setValue:nestedDictObj forKey:newKey]; - } - // Else, it is an object - else { - objc_property_t property = class_getProperty([NSClassFromString(propertyName) class], [newKey UTF8String]); - NSString *classType = [self typeFromProperty:property]; - // check if NSDate or not - if ([classType isEqualToString:@"T@\"NSDate\""]) { - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:OMDateFormat]; - [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]]; - NSString *dateString = [[nestedArray[xx] objectForKey:newKey] stringByReplacingOccurrencesOfString:@"T" withString:@" "]; - [nestedObj setValue:[formatter dateFromString:dateString] forKey:newKey]; - } - else { - [nestedObj setValue:[nestedArray[xx] objectForKey:newKey] forKey:newKey]; - } - } - } - - // Finally add that object - [objectsArray addObject:nestedObj]; - } - - // If it's an NSArray, recur - else if ([nestedArray[xx] isKindOfClass:[NSArray class]]) { - [objectsArray addObject:[NSObject arrayMapFromArray:nestedArray[xx] forPropertyName:propertyName]]; - } - - // Else, add object directly - else { - [objectsArray addObject:nestedArray[xx]]; - } - } - - // This is now an Array of objects - return objectsArray; -} - --(NSDictionary *)propertyDictionary { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - - unsigned count; - objc_property_t *properties = class_copyPropertyList([self class], &count); - - for (int i = 0; i < count; i++) { - NSString *key = [NSString stringWithUTF8String:property_getName(properties[i])]; - [dict setObject:key forKey:key]; - } - - free(properties); - - // Add all superclass properties as well, until it hits NSObject - NSString *superClassName = [[self superclass] nameOfClass]; - if (![superClassName isEqualToString:@"NSObject"]) { - for (NSString *property in [[[self superclass] propertyDictionary] allKeys]) { - [dict setObject:property forKey:property]; - } - } - - return dict; -} - --(NSString *)typeFromProperty:(objc_property_t)property { - return [[NSString stringWithUTF8String:property_getAttributes(property)] componentsSeparatedByString:@","][0]; -} - - -#pragma mark - Get Property Array Map -// This returns an associated property Dictionary for objects -// You should make an object contain a dictionary in init -// that contains a map for each array and what it contains: -// -// {"arrayPropertyName":"TypeOfObjectYouWantInArray"} -// -// To Set this object in each init method, do something like this: -// -// [myObject setValue:@"TypeOfObjectYouWantInArray" forKeyPath:@"propertyArrayMap.arrayPropertyName"] -// --(NSMutableDictionary *)getPropertyArrayMap { - if (objc_getAssociatedObject(self, @"propertyArrayMap")==nil) { - objc_setAssociatedObject(self,@"propertyArrayMap",[[NSMutableDictionary alloc] init],OBJC_ASSOCIATION_RETAIN); - } - return (NSMutableDictionary *)objc_getAssociatedObject(self, @"propertyArrayMap"); -} - - -#pragma mark - Copy NSObject (initWithObject) --(id)initWithObject:(NSObject *)oldObject error:(NSError **)error { - NSString *oldClassName = [oldObject nameOfClass]; - NSString *newClassName = [self nameOfClass]; - - if ([newClassName isEqualToString:oldClassName]) { - for (NSString *propertyKey in [[oldObject propertyDictionary] allKeys]) { - [self setValue:[oldObject valueForKey:propertyKey] forKey:propertyKey]; - } - } - else { - *error = [NSError errorWithDomain:@"MismatchedObjects" code:404 userInfo:@{@"Error":@"Mismatched Object Classes"}]; - } - - return self; -} - - -#pragma mark - Object to Data/String/etc. - --(NSDictionary *)objectDictionary { - NSMutableDictionary *objectDict = [@{} mutableCopy]; - for (NSString *key in [[self propertyDictionary] allKeys]) { - [objectDict setValue:[self valueForKey:key] forKey:key]; - } - return objectDict; -} - --(NSData *)JSONData{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil]; -} - --(NSString *)JSONString{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - NSData *JSONData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil]; - return [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding]; -} - -+(NSDictionary *) dictionaryWithPropertiesOfObject:(id)obj -{ - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - - NSMutableArray *propertiesArray = [NSObject propertiesArrayFromObject:obj]; - - for (int i = 0; i < propertiesArray.count; i++) { - NSString *key = propertiesArray[i]; - - if ([self isArray:obj key:key]) { - [dict setObject:[self arrayForObject:[obj valueForKey:key]] forKey:key]; - } - else if ([self isDate:[obj valueForKey:key]]){ - [dict setObject:[self dateForObject:[obj valueForKey:key]] forKey:key]; - } - else if ([self isSystemObject:obj key:key]) { - [dict setObject:[obj valueForKey:key] forKey:key]; - } - else if ([NSObject isData:[obj valueForKey:key]]){ - [dict setObject:[NSObject encodeBase64WithData:[obj valueForKey:key]] forKey:key]; - } - else { - [dict setObject:[self dictionaryWithPropertiesOfObject:[obj valueForKey:key]] forKey:key]; - } - } - - return [NSDictionary dictionaryWithDictionary:dict]; -} - -+(NSMutableArray *)propertiesArrayFromObject:(id)obj { - - NSMutableArray *props = [NSMutableArray array]; - - if (!obj) { - return props; - } - - unsigned count; - objc_property_t *properties = class_copyPropertyList([obj class], &count); - for (int i = 0; i < count; i++) { - [props addObject:[NSString stringWithUTF8String:property_getName(properties[i])]]; - } - - free(properties); - - NSString *superClassName = [[obj superclass] nameOfClass]; - if (![superClassName isEqualToString:@"NSObject"]) { - [props addObjectsFromArray:[NSObject propertiesArrayFromObject:[[NSClassFromString(superClassName) alloc] init]]]; - } - - return props; -} - --(BOOL)isSystemObject:(id)obj key:(NSString *)key{ - if ([[obj valueForKey:key] isKindOfClass:[NSString class]] || [[obj valueForKey:key] isKindOfClass:[NSNumber class]]) { - return YES; - } - - return NO; -} - --(BOOL)isSystemObject:(id)obj{ - if ([obj isKindOfClass:[NSString class]] || [obj isKindOfClass:[NSNumber class]]) { - return YES; - } - - return NO; -} - --(BOOL)isArray:(id)obj key:(NSString *)key{ - if ([[obj valueForKey:key] isKindOfClass:[NSArray class]]) { - return YES; - } - - return NO; -} - --(BOOL)isArray:(id)obj{ - if ([obj isKindOfClass:[NSArray class]]) { - return YES; - } - - return NO; -} - -+(BOOL)isDate:(id)obj{ - if ([obj isKindOfClass:[NSDate class]]) { - return YES; - } - - return NO; -} - -+(BOOL)isData:(id)obj{ - if ([obj isKindOfClass:[NSData class]]) { - return YES; - } - - return NO; -} - --(BOOL)isData:(id)obj{ - if ([obj isKindOfClass:[NSData class]]) { - return YES; - } - - return NO; -} - -+(NSArray *)arrayForObject:(id)obj{ - NSArray *ContentArray = (NSArray *)obj; - NSMutableArray *objectsArray = [[NSMutableArray alloc] init]; - for (int ii = 0; ii < ContentArray.count; ii++) { - if ([self isArray:ContentArray[ii]]) { - [objectsArray addObject:[self arrayForObject:[ContentArray objectAtIndex:ii]]]; - } - else if ([self isDate:ContentArray[ii]]){ - [objectsArray addObject:[self dateForObject:[ContentArray objectAtIndex:ii]]]; - } - else if ([self isSystemObject:[ContentArray objectAtIndex:ii]]) { - [objectsArray addObject:[ContentArray objectAtIndex:ii]]; - } - else { - [objectsArray addObject:[self dictionaryWithPropertiesOfObject:[ContentArray objectAtIndex:ii]]]; - } - - } - - return objectsArray; -} - - -+(NSString *)dateForObject:(id)obj{ - NSDate *date = (NSDate *)obj; - - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:OMDateFormat]; - [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]]; - return [formatter stringFromDate:date]; -} - -#pragma mark - SOAP/XML Serialization - --(NSData *)SOAPData{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [[self soapStringFroDictionary:dict] dataUsingEncoding:NSUTF8StringEncoding]; -} - --(NSData *)XMLData{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [[self xmlStringForSelfDictionary:dict] dataUsingEncoding:NSUTF8StringEncoding]; -} - --(NSString *)XMLString{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [self xmlStringForSelfDictionary:dict]; -} - --(NSString *)SOAPString{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [self soapStringFroDictionary:dict]; -} - --(NSString *)soapStringFroDictionary:(NSDictionary *)dict{ - SOAPObject *soapObject = (SOAPObject *)self; - - NSMutableString *soapString = [[NSMutableString alloc] initWithString:@""]; - - //Open Envelope - [soapString appendString:@""]; - - //Request Header - if ([dict valueForKey:@"Header"]) { - - - - //Append containing class name - if (soapObject.Header) { - [soapString appendString:@""]; - [soapString appendFormat:@"<%s>", class_getName([soapObject.Header class])]; - } - - - NSDictionary *headerDict = [dict valueForKey:@"Header"]; - //Append object contents - for (id key in headerDict) { - [soapString appendFormat:@"<%@>", (NSString *)key]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:headerDict key:key]]; - [soapString appendFormat:@"", (NSString *)key]; - } - - //Close containing class name - if (soapObject.Header) { - [soapString appendFormat:@"", class_getName([soapObject.Header class])]; - [soapString appendString:@""]; - } - - - - } - - - if ([dict valueForKey:@"Body"]) { - [soapString appendString:@""]; - - //Append containing class name - if (soapObject.Body) { - [soapString appendFormat:@"<%s>", class_getName([soapObject.Body class])]; - } - - NSDictionary *bodyDict = [dict valueForKey:@"Body"]; - //NSLog(@"\n\nSOAP Body: %@\n\n", bodyDict); - //Append object contents - for (id key in bodyDict) { - [soapString appendFormat:@"<%@>", (NSString *)key]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:bodyDict key:key]]; - [soapString appendFormat:@"", (NSString *)key]; - } - - //Close containing class name - if (soapObject.Body) { - [soapString appendFormat:@"", class_getName([soapObject.Body class])]; - } - - [soapString appendString:@""]; - } - - //Close Envelope - [soapString appendString:@""]; - - return soapString; -} - --(NSString *)xmlStringForSelfDictionary:(NSDictionary *)dict{ - NSMutableString *xmlString = [[NSMutableString alloc] initWithString:@""]; - - //Document Header - [xmlString appendString:@""]; - - //Append containing class name - [xmlString appendFormat:@"<%s>", class_getName([self class])]; - - //Fill in all values - for (id key in dict) { - [xmlString appendFormat:@"<%@>", (NSString *)key]; - [xmlString appendFormat:@"%@", [self xmlStringForDictionary:dict key:key]]; - [xmlString appendFormat:@"", (NSString *)key]; - } - - //Close containing class name - [xmlString appendFormat:@"", class_getName([self class])]; - - return xmlString; -} - - --(NSString *)xmlStringForDictionary:(NSDictionary *)dict key:(NSString *)key{ - NSMutableString *soapString = [[NSMutableString alloc] initWithString:@""]; - - if ([[dict valueForKey:key] isKindOfClass:[NSDate class]]) { - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:OMDateFormat]; - [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]]; - return [formatter stringFromDate:[dict valueForKey:key]]; - - return [dict valueForKey:key]; - } - else if ([[dict valueForKey:key] isKindOfClass:[NSData class]]){ - return [NSObject encodeBase64WithData:[dict valueForKey:key]]; - } - else if ([[dict valueForKey:key] isKindOfClass:[NSArray class]]) { - NSArray *childArray = [dict valueForKey:key]; - for (int ii = 0; ii < childArray.count; ii++) { - NSString *className = [key stringByReplacingOccurrencesOfString:@"ArrayOf" withString:@""]; - - if ([childArray[ii] isKindOfClass:[NSString class]]) { - [soapString appendString:@""]; - [soapString appendFormat:@"%@", childArray[ii]]; - [soapString appendString:@""]; - } - else { - [soapString appendFormat:@"<%@>", className]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:childArray[ii]]]; - [soapString appendFormat:@"", className]; - } - - - } - } - else if ([[dict valueForKey:key] isKindOfClass:[NSDictionary class]]) { - NSDictionary *childDictionary = [dict valueForKey:key]; - for (id childKey in [dict valueForKey:key]) { - [soapString appendFormat:@"<%@>", (NSString *)childKey]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:childDictionary key:childKey]]; - [soapString appendFormat:@"", (NSString *)childKey]; - } - } - - else { - return [dict valueForKey:key]; - } - - return soapString; -} - --(NSString *)xmlStringForDictionary:(NSDictionary *)dict{ - NSMutableString *soapString = [[NSMutableString alloc] initWithString:@""]; - - for (id key in dict) { - [soapString appendFormat:@"<%@>", (NSString *)key]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:dict key:key]]; - [soapString appendFormat:@"", (NSString *)key]; - } - - return soapString; -} - - -#pragma mark - Base64 Binary Encode/Decode - -+(NSData *)base64DataFromString:(NSString *)string -{ - unsigned long ixtext, lentext; - unsigned char ch, inbuf[4], outbuf[3]; - short i, ixinbuf; - Boolean flignore, flendtext = false; - const unsigned char *tempcstring; - NSMutableData *theData; - - if (string == nil) - { - return [NSData data]; - } - - ixtext = 0; - - tempcstring = (const unsigned char *)[string UTF8String]; - - lentext = [string length]; - - theData = [NSMutableData dataWithCapacity: lentext]; - - ixinbuf = 0; - - while (true) - { - if (ixtext >= lentext) - { - break; - } - - ch = tempcstring [ixtext++]; - - flignore = false; - - if ((ch >= 'A') && (ch <= 'Z')) - { - ch = ch - 'A'; - } - else if ((ch >= 'a') && (ch <= 'z')) - { - ch = ch - 'a' + 26; - } - else if ((ch >= '0') && (ch <= '9')) - { - ch = ch - '0' + 52; - } - else if (ch == '+') - { - ch = 62; - } - else if (ch == '=') - { - flendtext = true; - } - else if (ch == '/') - { - ch = 63; - } - else - { - flignore = true; - } - - if (!flignore) - { - short ctcharsinbuf = 3; - Boolean flbreak = false; - - if (flendtext) - { - if (ixinbuf == 0) - { - break; - } - - if ((ixinbuf == 1) || (ixinbuf == 2)) - { - ctcharsinbuf = 1; - } - else - { - ctcharsinbuf = 2; - } - - ixinbuf = 3; - - flbreak = true; - } - - inbuf [ixinbuf++] = ch; - - if (ixinbuf == 4) - { - ixinbuf = 0; - - outbuf[0] = (inbuf[0] << 2) | ((inbuf[1] & 0x30) >> 4); - outbuf[1] = ((inbuf[1] & 0x0F) << 4) | ((inbuf[2] & 0x3C) >> 2); - outbuf[2] = ((inbuf[2] & 0x03) << 6) | (inbuf[3] & 0x3F); - - for (i = 0; i < ctcharsinbuf; i++) - { - [theData appendBytes: &outbuf[i] length: 1]; - } - } - - if (flbreak) - { - break; - } - } - } - - return theData; -} - -+ (NSString *)encodeBase64WithData:(NSData *)objData { - const unsigned char * objRawData = [objData bytes]; - char * objPointer; - char * strResult; - - // Get the Raw Data length and ensure we actually have data - int intLength = [objData length]; - if (intLength == 0) return nil; - - // Setup the String-based Result placeholder and pointer within that placeholder - strResult = (char *)calloc(((intLength + 2) / 3) * 4, sizeof(char)); - objPointer = strResult; - - // Iterate through everything - while (intLength > 2) { // keep going until we have less than 24 bits - *objPointer++ = _base64EncodingTable[objRawData[0] >> 2]; - *objPointer++ = _base64EncodingTable[((objRawData[0] & 0x03) << 4) + (objRawData[1] >> 4)]; - *objPointer++ = _base64EncodingTable[((objRawData[1] & 0x0f) << 2) + (objRawData[2] >> 6)]; - *objPointer++ = _base64EncodingTable[objRawData[2] & 0x3f]; - - // we just handled 3 octets (24 bits) of data - objRawData += 3; - intLength -= 3; - } - - // now deal with the tail end of things - if (intLength != 0) { - *objPointer++ = _base64EncodingTable[objRawData[0] >> 2]; - if (intLength > 1) { - *objPointer++ = _base64EncodingTable[((objRawData[0] & 0x03) << 4) + (objRawData[1] >> 4)]; - *objPointer++ = _base64EncodingTable[(objRawData[1] & 0x0f) << 2]; - *objPointer++ = '='; - } else { - *objPointer++ = _base64EncodingTable[(objRawData[0] & 0x03) << 4]; - *objPointer++ = '='; - *objPointer++ = '='; - } - } - - // Terminate the string-based result - *objPointer = '\0'; - - // Return the results as an NSString object - return [NSString stringWithCString:strResult encoding:NSUTF8StringEncoding]; -} - - - -@end - - -@implementation SOAPObject - -@end diff --git a/Demos/WeatherXMLDemo/WeatherXMLDemo.xcodeproj/project.pbxproj b/Demos/WeatherXMLDemo/WeatherXMLDemo.xcodeproj/project.pbxproj index d712c3a..b35bf1f 100644 --- a/Demos/WeatherXMLDemo/WeatherXMLDemo.xcodeproj/project.pbxproj +++ b/Demos/WeatherXMLDemo/WeatherXMLDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + B6F7E06D18C61FCE00EBD65F /* NSObject+ObjectMap.m in Sources */ = {isa = PBXBuildFile; fileRef = B6F7E06C18C61FCE00EBD65F /* NSObject+ObjectMap.m */; }; BBCCAC3617AA97A6008EA33B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBCCAC3517AA97A6008EA33B /* UIKit.framework */; }; BBCCAC3817AA97A6008EA33B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBCCAC3717AA97A6008EA33B /* Foundation.framework */; }; BBCCAC3A17AA97A6008EA33B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBCCAC3917AA97A6008EA33B /* CoreGraphics.framework */; }; @@ -18,7 +19,6 @@ BBCCAC4C17AA97A6008EA33B /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BBCCAC4B17AA97A6008EA33B /* Default-568h@2x.png */; }; BBCCAC4F17AA97A6008EA33B /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = BBCCAC4E17AA97A6008EA33B /* ViewController.m */; }; BBCCAC5217AA97A6008EA33B /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BBCCAC5017AA97A6008EA33B /* ViewController.xib */; }; - BBCCAC5B17AA97E1008EA33B /* NSObject+ObjectMap.m in Sources */ = {isa = PBXBuildFile; fileRef = BBCCAC5A17AA97E1008EA33B /* NSObject+ObjectMap.m */; }; BBCCAC6017AA98E3008EA33B /* WebService.m in Sources */ = {isa = PBXBuildFile; fileRef = BBCCAC5F17AA98E3008EA33B /* WebService.m */; }; BBCCAC6317AA9FDF008EA33B /* current_condition.m in Sources */ = {isa = PBXBuildFile; fileRef = BBCCAC6217AA9FDF008EA33B /* current_condition.m */; }; BBCCAC6617AAA0D4008EA33B /* request.m in Sources */ = {isa = PBXBuildFile; fileRef = BBCCAC6517AAA0D4008EA33B /* request.m */; }; @@ -28,6 +28,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + B6F7E06B18C61FCE00EBD65F /* NSObject+ObjectMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSObject+ObjectMap.h"; path = "../../../NSObject-ObjectMap/NSObject+ObjectMap.h"; sourceTree = ""; }; + B6F7E06C18C61FCE00EBD65F /* NSObject+ObjectMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSObject+ObjectMap.m"; path = "../../../NSObject-ObjectMap/NSObject+ObjectMap.m"; sourceTree = ""; }; BBCCAC3217AA97A6008EA33B /* WeatherXMLDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WeatherXMLDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; BBCCAC3517AA97A6008EA33B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; BBCCAC3717AA97A6008EA33B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -44,8 +46,6 @@ BBCCAC4D17AA97A6008EA33B /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; BBCCAC4E17AA97A6008EA33B /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; BBCCAC5117AA97A6008EA33B /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = ""; }; - BBCCAC5917AA97E1008EA33B /* NSObject+ObjectMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+ObjectMap.h"; sourceTree = ""; }; - BBCCAC5A17AA97E1008EA33B /* NSObject+ObjectMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+ObjectMap.m"; sourceTree = ""; }; BBCCAC5E17AA98E3008EA33B /* WebService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebService.h; sourceTree = ""; }; BBCCAC5F17AA98E3008EA33B /* WebService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebService.m; sourceTree = ""; }; BBCCAC6117AA9FDF008EA33B /* current_condition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = current_condition.h; sourceTree = ""; }; @@ -134,8 +134,8 @@ BBCCAC5817AA97B6008EA33B /* NSObject+ObjectMap */ = { isa = PBXGroup; children = ( - BBCCAC5917AA97E1008EA33B /* NSObject+ObjectMap.h */, - BBCCAC5A17AA97E1008EA33B /* NSObject+ObjectMap.m */, + B6F7E06B18C61FCE00EBD65F /* NSObject+ObjectMap.h */, + B6F7E06C18C61FCE00EBD65F /* NSObject+ObjectMap.m */, ); name = "NSObject+ObjectMap"; sourceTree = ""; @@ -234,12 +234,12 @@ BBCCAC4217AA97A6008EA33B /* main.m in Sources */, BBCCAC4617AA97A6008EA33B /* AppDelegate.m in Sources */, BBCCAC4F17AA97A6008EA33B /* ViewController.m in Sources */, - BBCCAC5B17AA97E1008EA33B /* NSObject+ObjectMap.m in Sources */, BBCCAC6017AA98E3008EA33B /* WebService.m in Sources */, BBCCAC6317AA9FDF008EA33B /* current_condition.m in Sources */, BBCCAC6617AAA0D4008EA33B /* request.m in Sources */, BBCCAC6917AAA0FF008EA33B /* weather.m in Sources */, BBCCAC6C17AAA171008EA33B /* data.m in Sources */, + B6F7E06D18C61FCE00EBD65F /* NSObject+ObjectMap.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Demos/WeatherXMLDemo/WeatherXMLDemo/NSObject+ObjectMap.h b/Demos/WeatherXMLDemo/WeatherXMLDemo/NSObject+ObjectMap.h deleted file mode 100644 index 1697532..0000000 --- a/Demos/WeatherXMLDemo/WeatherXMLDemo/NSObject+ObjectMap.h +++ /dev/null @@ -1,55 +0,0 @@ -// -// NSObject+JSONMap.h -// TenEight -// -// Created by Benjamin Gordon on 5/8/13. -// Copyright (c) 2013 Matthew York. All rights reserved. -// - -#import -#import - -#define OMDateFormat @"yyyy-MM-dd'T'HH:mm:ss.SSS" -#define OMTimeZone @"UTC" - -@interface NSObject (ObjectMap) - -// Universal Method --(NSDictionary *)propertyDictionary; --(NSString *)nameOfClass; - -// id -> Object -+(id)objectOfClass:(NSString *)object fromJSON:(NSDictionary *)dict; -+(NSArray *)arrayFromJSON:(NSArray *)jsonArray ofObjects:(NSString *)obj; - -//Object -> Data --(NSDictionary *)objectDictionary; --(NSData *)JSONData; --(NSString *)JSONString; - -// XML-SOAP --(NSData *)XMLData; --(NSString *)XMLString; --(NSData *)SOAPData; --(NSString *)SOAPString; -+(id)objectOfClass:(NSString *)object fromXML:(NSString *)xml; - - -// For mapping an array to properties --(NSMutableDictionary *)getPropertyArrayMap; - - -// Copying an NSObject to new memory ref -// (basically initWithObject) --(id)initWithObject:(NSObject *)oldObject error:(NSError **)error; - -// Base64 Encode/Decode -+(NSString *)encodeBase64WithData:(NSData *)objData; -+(NSData *)base64DataFromString:(NSString *)string; - -@end - -@interface SOAPObject : NSObject -@property (nonatomic, retain) id Header; -@property (nonatomic, retain) id Body; -@end \ No newline at end of file diff --git a/Demos/WeatherXMLDemo/WeatherXMLDemo/NSObject+ObjectMap.m b/Demos/WeatherXMLDemo/WeatherXMLDemo/NSObject+ObjectMap.m deleted file mode 100644 index bacabe9..0000000 --- a/Demos/WeatherXMLDemo/WeatherXMLDemo/NSObject+ObjectMap.m +++ /dev/null @@ -1,915 +0,0 @@ -// -// NSObject+JSONMap.m -// TenEight -// -// Created by Benjamin Gordon on 5/8/13. -// Copyright (c) 2013 Matthew York. All rights reserved. -// - -#import "NSObject+ObjectMap.h" - -static const char _base64EncodingTable[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const short _base64DecodingTable[256] = { - -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -1, -1, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -2, -2, -2, - -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, -2, - -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 -}; - - -@implementation NSObject (ObjectMap) - -#pragma mark - XML to Object -+(id)objectOfClass:(NSString *)object fromXML:(NSString *)xml { - id newObject = [[NSClassFromString(object) alloc] init]; - - NSDictionary *mapDictionary = [newObject propertyDictionary]; - - for (NSString *key in [mapDictionary allKeys]) { - objc_property_t property = class_getProperty([newObject class], [key UTF8String]); - NSString *className = [[newObject typeFromProperty:property] substringWithRange:NSMakeRange(3, [newObject typeFromProperty:property].length - 4)]; - id objForKey; - - // Check Types - if ([className isEqualToString:@"NSString"]) { - objForKey = [[NSString alloc] init]; - } - else if ([className isEqualToString:@"NSDate"]) { - objForKey = [NSDate date]; - } - else if ([className isEqualToString:@"NSNumber"]) { - objForKey = [[NSNumber alloc] initWithFloat:0.00]; - } - else if ([className isEqualToString:@"NSArray"]) { - objForKey = [[NSArray alloc] init]; - } - else if ([className isEqualToString:@"NSData"]){ - objForKey = [[NSData alloc] init]; - } - else { - objForKey = [[NSClassFromString(className) alloc] init]; - } - - // Create - [newObject setValue:[objForKey getNodeValue:key fromXML:xml] forKey:key]; - } - - return newObject; -} - --(id)getNodeValue:(NSString *)node fromXML:(NSString *)xml { - NSString *trash = @""; - NSString *value = @""; - NSScanner *xmlScanner = [NSScanner scannerWithString:xml]; - [xmlScanner scanUpToString:[NSString stringWithFormat:@"<%@", node] intoString:&trash]; - [xmlScanner scanUpToString:@">" intoString:&trash]; - [xmlScanner scanString:@">" intoString:&trash]; - - // Check property type - if ([self isKindOfClass:[NSArray class]]) { - // Set up a new scanner for xml substring - [xmlScanner scanUpToString:[NSString stringWithFormat:@"" intoString:&filteredArrayObj]; - NSScanner *insideArrayScanner = [NSScanner scannerWithString:value]; - NSString *newValue = @""; - NSMutableArray *objArray = [@[] mutableCopy]; - - // Scan and create objects until you can't no mo' - while (![insideArrayScanner isAtEnd]) { - [insideArrayScanner scanUpToString:[NSString stringWithFormat:@"<%@", filteredArrayObj] intoString:&trash]; - [insideArrayScanner scanUpToString:@">" intoString:&trash]; - [insideArrayScanner scanString:@">" intoString:&trash]; - [insideArrayScanner scanUpToString:[NSString stringWithFormat:@"" intoString:&trash]; - [insideArrayScanner scanString:@">" intoString:&trash]; - } - - // Return the array - return objArray; - } - - else if ([self isKindOfClass:[NSNumber class]]) { - [xmlScanner scanUpToString:@" make into object/id - else if ([[dict objectForKey:key] isKindOfClass:[NSArray class]]) { - NSArray *nestedArray = [dict objectForKey:key]; - NSString *propertyType = [newObject valueForKeyPath:[NSString stringWithFormat:@"propertyArrayMap.%@", key]]; - [newObject setValue:[NSObject arrayMapFromArray:nestedArray forPropertyName:propertyType] forKey:propertyName]; - } - - // Add to property name, because it is a type already - else { - objc_property_t property = class_getProperty([newObject class], [propertyName UTF8String]); - NSString *classType = [newObject typeFromProperty:property]; - - // check if NSDate or not - if ([classType isEqualToString:@"T@\"NSDate\""]) { - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:OMDateFormat]; - [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]]; - NSString *dateString = [[dict objectForKey:key] stringByReplacingOccurrencesOfString:@"T" withString:@" "]; - [newObject setValue:[formatter dateFromString:dateString] forKey:propertyName]; - } - else { - if ([dict objectForKey:key] != [NSNull null]) { - [newObject setValue:[dict objectForKey:key] forKey:propertyName]; - } - else { - [newObject setValue:nil forKey:propertyName]; - } - } - } - } - - return newObject; -} - --(NSString *)classOfPropertyNamed:(NSString *)propName { - unsigned count; - objc_property_t *properties = class_copyPropertyList([self class], &count); - - for (int xx = 0; xx < count; xx++) { - if ([[NSString stringWithUTF8String:property_getName(properties[xx])] isEqualToString:propName]) { - NSString *className = [NSString stringWithFormat:@"%s", getPropertyType(properties[xx])]; - free(properties); - return className; - } - } - - return nil; -} - - -static const char * getPropertyType(objc_property_t property) { - const char *attributes = property_getAttributes(property); - printf("attributes=%s\n", attributes); - char buffer[1 + strlen(attributes)]; - strcpy(buffer, attributes); - char *state = buffer, *attribute; - while ((attribute = strsep(&state, ",")) != NULL) { - if (attribute[0] == 'T' && attribute[1] != '@') { - // it's a C primitive type: - /* - if you want a list of what will be returned for these primitives, search online for - "objective-c" "Property Attribute Description Examples" - apple docs list plenty of examples of what you get for int "i", long "l", unsigned "I", struct, etc. - */ - return (const char *)[[NSData dataWithBytes:(attribute + 1) length:strlen(attribute) - 1] bytes]; - } - else if (attribute[0] == 'T' && attribute[1] == '@' && strlen(attribute) == 2) { - // it's an ObjC id type: - return "id"; - } - else if (attribute[0] == 'T' && attribute[1] == '@') { - // it's another ObjC object type: - return (const char *)[[NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4] bytes]; - } - } - return ""; -} - -+(NSArray *)arrayFromJSON:(NSArray *)jsonArray ofObjects:(NSString *)obj { - //NSString *filteredObject = [NSString stringWithFormat:@"%@s",obj]; - return [NSObject arrayMapFromArray:jsonArray forPropertyName:obj]; -} - --(NSString *)nameOfClass { - return [NSString stringWithUTF8String:class_getName([self class])]; -} - -+(NSArray *)arrayMapFromArray:(NSArray *)nestedArray forPropertyName:(NSString *)propertyName { - // Set Up - NSMutableArray *objectsArray = [@[] mutableCopy]; - - // Removes "ArrayOf(PropertyName)s" to get to the meat - //NSString *filteredProperty = [propertyName substringWithRange:NSMakeRange(0, propertyName.length - 1)]; /* TenEight */ - //NSString *filteredProperty = [propertyName substringWithRange:NSMakeRange(7, propertyName.length - 8)]; /* AlaCop */ - - // Create objects - for (int xx = 0; xx < nestedArray.count; xx++) { - // If it's an NSDictionary - if ([nestedArray[xx] isKindOfClass:[NSDictionary class]]) { - // Create object of filteredProperty type - id nestedObj = [[NSClassFromString(propertyName) alloc] init]; - - // Iterate through each key, create objects for each - for (NSString *newKey in [nestedArray[xx] allKeys]) { - // If it's an Array, recur - if ([[nestedArray[xx] objectForKey:newKey] isKindOfClass:[NSArray class]]) { - NSString *propertyType = [nestedObj valueForKeyPath:[NSString stringWithFormat:@"propertyArrayMap.%@", newKey]]; - [nestedObj setValue:[NSObject arrayMapFromArray:[nestedArray[xx] objectForKey:newKey] forPropertyName:propertyType] forKey:newKey]; - } - // If it's a Dictionary, create an object, and send to [self objectFromJSON] - else if ([[nestedArray[xx] objectForKey:newKey] isKindOfClass:[NSDictionary class]]) { - NSString *type = [nestedObj classOfPropertyNamed:newKey]; - - id nestedDictObj = [NSObject objectOfClass:type fromJSON:[nestedArray[xx] objectForKey:newKey]]; - [nestedObj setValue:nestedDictObj forKey:newKey]; - } - // Else, it is an object - else { - objc_property_t property = class_getProperty([NSClassFromString(propertyName) class], [newKey UTF8String]); - NSString *classType = [self typeFromProperty:property]; - // check if NSDate or not - if ([classType isEqualToString:@"T@\"NSDate\""]) { - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:OMDateFormat]; - [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]]; - NSString *dateString = [[nestedArray[xx] objectForKey:newKey] stringByReplacingOccurrencesOfString:@"T" withString:@" "]; - [nestedObj setValue:[formatter dateFromString:dateString] forKey:newKey]; - } - else { - [nestedObj setValue:[nestedArray[xx] objectForKey:newKey] forKey:newKey]; - } - } - } - - // Finally add that object - [objectsArray addObject:nestedObj]; - } - - // If it's an NSArray, recur - else if ([nestedArray[xx] isKindOfClass:[NSArray class]]) { - [objectsArray addObject:[NSObject arrayMapFromArray:nestedArray[xx] forPropertyName:propertyName]]; - } - - // Else, add object directly - else { - [objectsArray addObject:nestedArray[xx]]; - } - } - - // This is now an Array of objects - return objectsArray; -} - --(NSDictionary *)propertyDictionary { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - - unsigned count; - objc_property_t *properties = class_copyPropertyList([self class], &count); - - for (int i = 0; i < count; i++) { - NSString *key = [NSString stringWithUTF8String:property_getName(properties[i])]; - [dict setObject:key forKey:key]; - } - - free(properties); - - // Add all superclass properties as well, until it hits NSObject - NSString *superClassName = [[self superclass] nameOfClass]; - if (![superClassName isEqualToString:@"NSObject"]) { - for (NSString *property in [[[self superclass] propertyDictionary] allKeys]) { - [dict setObject:property forKey:property]; - } - } - - return dict; -} - --(NSString *)typeFromProperty:(objc_property_t)property { - return [[NSString stringWithUTF8String:property_getAttributes(property)] componentsSeparatedByString:@","][0]; -} - - -#pragma mark - Get Property Array Map -// This returns an associated property Dictionary for objects -// You should make an object contain a dictionary in init -// that contains a map for each array and what it contains: -// -// {"arrayPropertyName":"TypeOfObjectYouWantInArray"} -// -// To Set this object in each init method, do something like this: -// -// [myObject setValue:@"TypeOfObjectYouWantInArray" forKeyPath:@"propertyArrayMap.arrayPropertyName"] -// --(NSMutableDictionary *)getPropertyArrayMap { - if (objc_getAssociatedObject(self, @"propertyArrayMap")==nil) { - objc_setAssociatedObject(self,@"propertyArrayMap",[[NSMutableDictionary alloc] init],OBJC_ASSOCIATION_RETAIN); - } - return (NSMutableDictionary *)objc_getAssociatedObject(self, @"propertyArrayMap"); -} - - -#pragma mark - Copy NSObject (initWithObject) --(id)initWithObject:(NSObject *)oldObject error:(NSError **)error { - NSString *oldClassName = [oldObject nameOfClass]; - NSString *newClassName = [self nameOfClass]; - - if ([newClassName isEqualToString:oldClassName]) { - for (NSString *propertyKey in [[oldObject propertyDictionary] allKeys]) { - [self setValue:[oldObject valueForKey:propertyKey] forKey:propertyKey]; - } - } - else { - *error = [NSError errorWithDomain:@"MismatchedObjects" code:404 userInfo:@{@"Error":@"Mismatched Object Classes"}]; - } - - return self; -} - - -#pragma mark - Object to Data/String/etc. - --(NSDictionary *)objectDictionary { - NSMutableDictionary *objectDict = [@{} mutableCopy]; - for (NSString *key in [[self propertyDictionary] allKeys]) { - [objectDict setValue:[self valueForKey:key] forKey:key]; - } - return objectDict; -} - --(NSData *)JSONData{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil]; -} - --(NSString *)JSONString{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - NSData *JSONData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil]; - return [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding]; -} - -+(NSDictionary *) dictionaryWithPropertiesOfObject:(id)obj -{ - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - - NSMutableArray *propertiesArray = [NSObject propertiesArrayFromObject:obj]; - - for (int i = 0; i < propertiesArray.count; i++) { - NSString *key = propertiesArray[i]; - - if ([self isArray:obj key:key]) { - [dict setObject:[self arrayForObject:[obj valueForKey:key]] forKey:key]; - } - else if ([self isDate:[obj valueForKey:key]]){ - [dict setObject:[self dateForObject:[obj valueForKey:key]] forKey:key]; - } - else if ([self isSystemObject:obj key:key]) { - [dict setObject:[obj valueForKey:key] forKey:key]; - } - else if ([NSObject isData:[obj valueForKey:key]]){ - [dict setObject:[NSObject encodeBase64WithData:[obj valueForKey:key]] forKey:key]; - } - else { - [dict setObject:[self dictionaryWithPropertiesOfObject:[obj valueForKey:key]] forKey:key]; - } - } - - return [NSDictionary dictionaryWithDictionary:dict]; -} - -+(NSMutableArray *)propertiesArrayFromObject:(id)obj { - - NSMutableArray *props = [NSMutableArray array]; - - if (!obj) { - return props; - } - - unsigned count; - objc_property_t *properties = class_copyPropertyList([obj class], &count); - for (int i = 0; i < count; i++) { - [props addObject:[NSString stringWithUTF8String:property_getName(properties[i])]]; - } - - free(properties); - - NSString *superClassName = [[obj superclass] nameOfClass]; - if (![superClassName isEqualToString:@"NSObject"]) { - [props addObjectsFromArray:[NSObject propertiesArrayFromObject:[[NSClassFromString(superClassName) alloc] init]]]; - } - - return props; -} - --(BOOL)isSystemObject:(id)obj key:(NSString *)key{ - if ([[obj valueForKey:key] isKindOfClass:[NSString class]] || [[obj valueForKey:key] isKindOfClass:[NSNumber class]]) { - return YES; - } - - return NO; -} - --(BOOL)isSystemObject:(id)obj{ - if ([obj isKindOfClass:[NSString class]] || [obj isKindOfClass:[NSNumber class]]) { - return YES; - } - - return NO; -} - --(BOOL)isArray:(id)obj key:(NSString *)key{ - if ([[obj valueForKey:key] isKindOfClass:[NSArray class]]) { - return YES; - } - - return NO; -} - --(BOOL)isArray:(id)obj{ - if ([obj isKindOfClass:[NSArray class]]) { - return YES; - } - - return NO; -} - -+(BOOL)isDate:(id)obj{ - if ([obj isKindOfClass:[NSDate class]]) { - return YES; - } - - return NO; -} - -+(BOOL)isData:(id)obj{ - if ([obj isKindOfClass:[NSData class]]) { - return YES; - } - - return NO; -} - --(BOOL)isData:(id)obj{ - if ([obj isKindOfClass:[NSData class]]) { - return YES; - } - - return NO; -} - -+(NSArray *)arrayForObject:(id)obj{ - NSArray *ContentArray = (NSArray *)obj; - NSMutableArray *objectsArray = [[NSMutableArray alloc] init]; - for (int ii = 0; ii < ContentArray.count; ii++) { - if ([self isArray:ContentArray[ii]]) { - [objectsArray addObject:[self arrayForObject:[ContentArray objectAtIndex:ii]]]; - } - else if ([self isDate:ContentArray[ii]]){ - [objectsArray addObject:[self dateForObject:[ContentArray objectAtIndex:ii]]]; - } - else if ([self isSystemObject:[ContentArray objectAtIndex:ii]]) { - [objectsArray addObject:[ContentArray objectAtIndex:ii]]; - } - else { - [objectsArray addObject:[self dictionaryWithPropertiesOfObject:[ContentArray objectAtIndex:ii]]]; - } - - } - - return objectsArray; -} - - -+(NSString *)dateForObject:(id)obj{ - NSDate *date = (NSDate *)obj; - - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:OMDateFormat]; - [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]]; - return [formatter stringFromDate:date]; -} - -#pragma mark - SOAP/XML Serialization - --(NSData *)SOAPData{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [[self soapStringFroDictionary:dict] dataUsingEncoding:NSUTF8StringEncoding]; -} - --(NSData *)XMLData{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [[self xmlStringForSelfDictionary:dict] dataUsingEncoding:NSUTF8StringEncoding]; -} - --(NSString *)XMLString{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [self xmlStringForSelfDictionary:dict]; -} - --(NSString *)SOAPString{ - NSDictionary *dict = [NSObject dictionaryWithPropertiesOfObject:self]; - return [self soapStringFroDictionary:dict]; -} - --(NSString *)soapStringFroDictionary:(NSDictionary *)dict{ - SOAPObject *soapObject = (SOAPObject *)self; - - NSMutableString *soapString = [[NSMutableString alloc] initWithString:@""]; - - //Open Envelope - [soapString appendString:@""]; - - //Request Header - if ([dict valueForKey:@"Header"]) { - - - - //Append containing class name - if (soapObject.Header) { - [soapString appendString:@""]; - [soapString appendFormat:@"<%s>", class_getName([soapObject.Header class])]; - } - - - NSDictionary *headerDict = [dict valueForKey:@"Header"]; - //Append object contents - for (id key in headerDict) { - [soapString appendFormat:@"<%@>", (NSString *)key]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:headerDict key:key]]; - [soapString appendFormat:@"", (NSString *)key]; - } - - //Close containing class name - if (soapObject.Header) { - [soapString appendFormat:@"", class_getName([soapObject.Header class])]; - [soapString appendString:@""]; - } - - - - } - - - if ([dict valueForKey:@"Body"]) { - [soapString appendString:@""]; - - //Append containing class name - if (soapObject.Body) { - [soapString appendFormat:@"<%s>", class_getName([soapObject.Body class])]; - } - - NSDictionary *bodyDict = [dict valueForKey:@"Body"]; - //NSLog(@"\n\nSOAP Body: %@\n\n", bodyDict); - //Append object contents - for (id key in bodyDict) { - [soapString appendFormat:@"<%@>", (NSString *)key]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:bodyDict key:key]]; - [soapString appendFormat:@"", (NSString *)key]; - } - - //Close containing class name - if (soapObject.Body) { - [soapString appendFormat:@"", class_getName([soapObject.Body class])]; - } - - [soapString appendString:@""]; - } - - //Close Envelope - [soapString appendString:@""]; - - return soapString; -} - --(NSString *)xmlStringForSelfDictionary:(NSDictionary *)dict{ - NSMutableString *xmlString = [[NSMutableString alloc] initWithString:@""]; - - //Document Header - [xmlString appendString:@""]; - - //Append containing class name - [xmlString appendFormat:@"<%s>", class_getName([self class])]; - - //Fill in all values - for (id key in dict) { - [xmlString appendFormat:@"<%@>", (NSString *)key]; - [xmlString appendFormat:@"%@", [self xmlStringForDictionary:dict key:key]]; - [xmlString appendFormat:@"", (NSString *)key]; - } - - //Close containing class name - [xmlString appendFormat:@"", class_getName([self class])]; - - return xmlString; -} - - --(NSString *)xmlStringForDictionary:(NSDictionary *)dict key:(NSString *)key{ - NSMutableString *soapString = [[NSMutableString alloc] initWithString:@""]; - - if ([[dict valueForKey:key] isKindOfClass:[NSDate class]]) { - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:OMDateFormat]; - [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]]; - return [formatter stringFromDate:[dict valueForKey:key]]; - - return [dict valueForKey:key]; - } - else if ([[dict valueForKey:key] isKindOfClass:[NSData class]]){ - return [NSObject encodeBase64WithData:[dict valueForKey:key]]; - } - else if ([[dict valueForKey:key] isKindOfClass:[NSArray class]]) { - NSArray *childArray = [dict valueForKey:key]; - for (int ii = 0; ii < childArray.count; ii++) { - NSString *className = [key stringByReplacingOccurrencesOfString:@"ArrayOf" withString:@""]; - - if ([childArray[ii] isKindOfClass:[NSString class]]) { - [soapString appendString:@""]; - [soapString appendFormat:@"%@", childArray[ii]]; - [soapString appendString:@""]; - } - else { - [soapString appendFormat:@"<%@>", className]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:childArray[ii]]]; - [soapString appendFormat:@"", className]; - } - - - } - } - else if ([[dict valueForKey:key] isKindOfClass:[NSDictionary class]]) { - NSDictionary *childDictionary = [dict valueForKey:key]; - for (id childKey in [dict valueForKey:key]) { - [soapString appendFormat:@"<%@>", (NSString *)childKey]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:childDictionary key:childKey]]; - [soapString appendFormat:@"", (NSString *)childKey]; - } - } - - else { - return [dict valueForKey:key]; - } - - return soapString; -} - --(NSString *)xmlStringForDictionary:(NSDictionary *)dict{ - NSMutableString *soapString = [[NSMutableString alloc] initWithString:@""]; - - for (id key in dict) { - [soapString appendFormat:@"<%@>", (NSString *)key]; - [soapString appendFormat:@"%@", [self xmlStringForDictionary:dict key:key]]; - [soapString appendFormat:@"", (NSString *)key]; - } - - return soapString; -} - - -#pragma mark - Base64 Binary Encode/Decode - -+(NSData *)base64DataFromString:(NSString *)string -{ - unsigned long ixtext, lentext; - unsigned char ch, inbuf[4], outbuf[3]; - short i, ixinbuf; - Boolean flignore, flendtext = false; - const unsigned char *tempcstring; - NSMutableData *theData; - - if (string == nil) - { - return [NSData data]; - } - - ixtext = 0; - - tempcstring = (const unsigned char *)[string UTF8String]; - - lentext = [string length]; - - theData = [NSMutableData dataWithCapacity: lentext]; - - ixinbuf = 0; - - while (true) - { - if (ixtext >= lentext) - { - break; - } - - ch = tempcstring [ixtext++]; - - flignore = false; - - if ((ch >= 'A') && (ch <= 'Z')) - { - ch = ch - 'A'; - } - else if ((ch >= 'a') && (ch <= 'z')) - { - ch = ch - 'a' + 26; - } - else if ((ch >= '0') && (ch <= '9')) - { - ch = ch - '0' + 52; - } - else if (ch == '+') - { - ch = 62; - } - else if (ch == '=') - { - flendtext = true; - } - else if (ch == '/') - { - ch = 63; - } - else - { - flignore = true; - } - - if (!flignore) - { - short ctcharsinbuf = 3; - Boolean flbreak = false; - - if (flendtext) - { - if (ixinbuf == 0) - { - break; - } - - if ((ixinbuf == 1) || (ixinbuf == 2)) - { - ctcharsinbuf = 1; - } - else - { - ctcharsinbuf = 2; - } - - ixinbuf = 3; - - flbreak = true; - } - - inbuf [ixinbuf++] = ch; - - if (ixinbuf == 4) - { - ixinbuf = 0; - - outbuf[0] = (inbuf[0] << 2) | ((inbuf[1] & 0x30) >> 4); - outbuf[1] = ((inbuf[1] & 0x0F) << 4) | ((inbuf[2] & 0x3C) >> 2); - outbuf[2] = ((inbuf[2] & 0x03) << 6) | (inbuf[3] & 0x3F); - - for (i = 0; i < ctcharsinbuf; i++) - { - [theData appendBytes: &outbuf[i] length: 1]; - } - } - - if (flbreak) - { - break; - } - } - } - - return theData; -} - -+ (NSString *)encodeBase64WithData:(NSData *)objData { - const unsigned char * objRawData = [objData bytes]; - char * objPointer; - char * strResult; - - // Get the Raw Data length and ensure we actually have data - int intLength = [objData length]; - if (intLength == 0) return nil; - - // Setup the String-based Result placeholder and pointer within that placeholder - strResult = (char *)calloc(((intLength + 2) / 3) * 4, sizeof(char)); - objPointer = strResult; - - // Iterate through everything - while (intLength > 2) { // keep going until we have less than 24 bits - *objPointer++ = _base64EncodingTable[objRawData[0] >> 2]; - *objPointer++ = _base64EncodingTable[((objRawData[0] & 0x03) << 4) + (objRawData[1] >> 4)]; - *objPointer++ = _base64EncodingTable[((objRawData[1] & 0x0f) << 2) + (objRawData[2] >> 6)]; - *objPointer++ = _base64EncodingTable[objRawData[2] & 0x3f]; - - // we just handled 3 octets (24 bits) of data - objRawData += 3; - intLength -= 3; - } - - // now deal with the tail end of things - if (intLength != 0) { - *objPointer++ = _base64EncodingTable[objRawData[0] >> 2]; - if (intLength > 1) { - *objPointer++ = _base64EncodingTable[((objRawData[0] & 0x03) << 4) + (objRawData[1] >> 4)]; - *objPointer++ = _base64EncodingTable[(objRawData[1] & 0x0f) << 2]; - *objPointer++ = '='; - } else { - *objPointer++ = _base64EncodingTable[(objRawData[0] & 0x03) << 4]; - *objPointer++ = '='; - *objPointer++ = '='; - } - } - - // Terminate the string-based result - *objPointer = '\0'; - - // Return the results as an NSString object - return [NSString stringWithCString:strResult encoding:NSUTF8StringEncoding]; -} - - - -@end - - -@implementation SOAPObject - -@end diff --git a/Demos/WeatherXMLDemo/WeatherXMLDemo/WebService.m b/Demos/WeatherXMLDemo/WeatherXMLDemo/WebService.m index b3c457c..b651e66 100644 --- a/Demos/WeatherXMLDemo/WeatherXMLDemo/WebService.m +++ b/Demos/WeatherXMLDemo/WeatherXMLDemo/WebService.m @@ -27,8 +27,7 @@ -(void)getWeatherDataForSearchTerm:(NSString *)searchTerm success:(RequestSucces __weak WeatherOperation *weakOp = operation; [operation setRequestWithSearch:searchTerm completion:^{ if (weakOp.responseData) { - NSString *xmlString = [[NSString alloc] initWithData:weakOp.responseData encoding:NSUTF8StringEncoding]; - data *weatherData = [NSObject objectOfClass:@"data" fromXML:xmlString]; + data *weatherData = [[data alloc] initWithXMLData:weakOp.responseData]; if (weatherData) { dispatch_async(dispatch_get_main_queue(), ^{ sBlock(weatherData); diff --git a/NSObject-ObjectMap.podspec b/NSObject-ObjectMap.podspec index d8d4902..990ce36 100644 --- a/NSObject-ObjectMap.podspec +++ b/NSObject-ObjectMap.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "NSObject-ObjectMap" - s.version = "2.0" + s.version = "2.1" s.summary = "This is a drop-in category of NSObject that makes it easy to initialize custom objects from JSON or XML." s.homepage = "https://github.com/uacaps/NSObject-ObjectMap" s.license = { :type => 'UA', :file => 'LICENSE' } s.author = { "uacaps" => "care@cs.ua.edu" } - s.source = { :git => "https://github.com/uacaps/NSObject-ObjectMap.git", :tag => "2.0" } + s.source = { :git => "https://github.com/uacaps/NSObject-ObjectMap.git", :tag => "2.1" } s.platform = :ios, '5.0' s.source_files = 'NSObject-ObjectMap/*.{h,m}' s.requires_arc = true diff --git a/NSObject-ObjectMap/NSObject+ObjectMap.m b/NSObject-ObjectMap/NSObject+ObjectMap.m index 49b56c8..80a01c6 100755 --- a/NSObject-ObjectMap/NSObject+ObjectMap.m +++ b/NSObject-ObjectMap/NSObject+ObjectMap.m @@ -53,7 +53,7 @@ @implementation NSScanner (XMLScan) -(BOOL)isAtEndOfTag:(NSString *)tag { - int scanPos = [self scanLocation]; + NSInteger scanPos = [self scanLocation]; NSString *trash = @""; [self scanUpToString:[NSString stringWithFormat:@" 0) { @@ -68,7 +68,7 @@ -(BOOL)isAtEndOfTag:(NSString *)tag { -(NSString *)nextXMLTag { NSString *trash = @"", *tag = @""; - int scanPos = [self scanLocation]; + NSInteger scanPos = [self scanLocation]; [self scanUpToString:@"<" intoString:&trash]; [self scanString:@"<" intoString:&trash]; if ([[self nextCharacter] isEqualToString:@"/"]) { @@ -84,7 +84,7 @@ -(NSString *)nextXMLTag { } -(NSString *)nextCharacter { - int scanPos = [self scanLocation]; + NSInteger scanPos = [self scanLocation]; if (scanPos < [self string].length - 1) { return [[self string] substringWithRange:NSMakeRange(scanPos+1, 1)]; } @@ -307,9 +307,9 @@ + (id)objectOfClass:(Class)objectClass fromJSONData:(NSData *)jsonData { } // Else it is an array of objects else if([jsonObject isKindOfClass:[NSArray class]]){ - int length = [((NSArray*) jsonObject) count]; + NSInteger length = [((NSArray*) jsonObject) count]; NSMutableArray *resultArray = [NSMutableArray arrayWithCapacity:length]; - for(int i = 0; i < length; i++){ + for(NSInteger i = 0; i < length; i++){ [resultArray addObject:[NSObject objectOfClass:objectClass fromJSON:[(NSArray*)jsonObject objectAtIndex:i]]]; } newObject = [[NSArray alloc] initWithArray:resultArray]; @@ -428,7 +428,7 @@ +(NSArray *)arrayMapFromArray:(NSArray *)nestedArray forPropertyName:(NSString * NSMutableArray *objectsArray = [@[] mutableCopy]; // Create objects - for (int xx = 0; xx < nestedArray.count; xx++) { + for (NSInteger xx = 0; xx < nestedArray.count; xx++) { // If it's an NSDictionary if ([nestedArray[xx] isKindOfClass:[NSDictionary class]]) { // Create object of filteredProperty type @@ -498,7 +498,7 @@ -(NSDictionary *)propertyDictionary { NSMutableDictionary *dict = [NSMutableDictionary dictionary]; unsigned count; objc_property_t *properties = class_copyPropertyList([self class], &count); - for (int i = 0; i < count; i++) { + for (NSInteger i = 0; i < count; i++) { NSString *key = [NSString stringWithUTF8String:property_getName(properties[i])]; [dict setObject:key forKey:key]; } @@ -583,9 +583,9 @@ -(NSString *)JSONString{ + (id)jsonDataObjects:(id)obj { id returnProperties = nil; if([self isArray:obj]) { - int length =[(NSArray*)obj count]; + NSInteger length =[(NSArray*)obj count]; returnProperties = [NSMutableArray arrayWithCapacity:length]; - for(int i = 0; i < length; i++){ + for(NSInteger i = 0; i < length; i++){ [returnProperties addObject:[NSObject dictionaryWithPropertiesOfObject:[(NSArray*)obj objectAtIndex:i]]]; } } @@ -603,7 +603,7 @@ +(NSDictionary *)dictionaryWithPropertiesOfObject:(id)obj NSMutableArray *propertiesArray = [NSObject propertiesArrayFromObject:obj]; - for (int i = 0; i < propertiesArray.count; i++) { + for (NSInteger i = 0; i < propertiesArray.count; i++) { NSString *key = propertiesArray[i]; if (![obj valueForKey:key]) { @@ -640,7 +640,7 @@ +(NSMutableArray *)propertiesArrayFromObject:(id)obj { unsigned count; objc_property_t *properties = class_copyPropertyList([obj class], &count); - for (int i = 0; i < count; i++) { + for (NSInteger i = 0; i < count; i++) { [props addObject:[NSString stringWithUTF8String:property_getName(properties[i])]]; } @@ -713,7 +713,7 @@ -(BOOL)isData:(id)obj{ +(NSArray *)arrayForObject:(id)obj{ NSArray *ContentArray = (NSArray *)obj; NSMutableArray *objectsArray = [[NSMutableArray alloc] init]; - for (int ii = 0; ii < ContentArray.count; ii++) { + for (NSInteger ii = 0; ii < ContentArray.count; ii++) { if ([self isArray:ContentArray[ii]]) { [objectsArray addObject:[self arrayForObject:[ContentArray objectAtIndex:ii]]]; } @@ -965,7 +965,7 @@ + (NSString *)encodeBase64WithData:(NSData *)objData { char * strResult; // Get the Raw Data length and ensure we actually have data - int intLength = [objData length]; + NSInteger intLength = [objData length]; if (intLength == 0) return nil; // Setup the String-based Result placeholder and pointer within that placeholder