Skip to content

Commit

Permalink
Merge pull request #5 from johankool/master
Browse files Browse the repository at this point in the history
Podspec update and project cleanup
  • Loading branch information
johankool committed Apr 1, 2014
2 parents ac05c72 + 7b59ac9 commit 3791eff
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 45 deletions.
2 changes: 1 addition & 1 deletion EFMapping.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "EFMapping"
s.version = "0.0.1"
s.version = "0.0.2"
s.summary = "Category on NSObject that maps data such as those coming from JSON onto an instance using mappings. The mappings are also used to simplify implementing the NSCoding protocol for a class, and to create a dictionary representation of an instance."
s.homepage = "https://github.com/Egeniq/EFMapping"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
96 changes: 56 additions & 40 deletions EFMapping.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
C70D5E0218DE0AE800E7B749 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C70D5E0118DE0AE800E7B749 /* Foundation.framework */; };
C70D5E0418DE0AE800E7B749 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C70D5E0318DE0AE800E7B749 /* CoreGraphics.framework */; };
C70D5E0618DE0AE800E7B749 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C70D5E0518DE0AE800E7B749 /* UIKit.framework */; };
C70D5E0C18DE0AE800E7B749 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C70D5E0A18DE0AE800E7B749 /* InfoPlist.strings */; };
C70D5E0E18DE0AE800E7B749 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C70D5E0D18DE0AE800E7B749 /* main.m */; };
C70D5E1218DE0AE800E7B749 /* EFAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C70D5E1118DE0AE800E7B749 /* EFAppDelegate.m */; };
C70D5E1418DE0AE800E7B749 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C70D5E1318DE0AE800E7B749 /* Images.xcassets */; };
C70D5E1B18DE0AE800E7B749 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C70D5E1A18DE0AE800E7B749 /* XCTest.framework */; };
C70D5E1C18DE0AE800E7B749 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C70D5E0118DE0AE800E7B749 /* Foundation.framework */; };
C70D5E1D18DE0AE800E7B749 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C70D5E0518DE0AE800E7B749 /* UIKit.framework */; };
C70D5E2518DE0AE900E7B749 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C70D5E2318DE0AE900E7B749 /* InfoPlist.strings */; };
C70D5E3218DE0B2A00E7B749 /* NSObject+EFMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = C70D5E3118DE0B2A00E7B749 /* NSObject+EFMapping.m */; };
C70D5E3418DE0B3A00E7B749 /* EFMappingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C70D5E3318DE0B3A00E7B749 /* EFMappingTest.m */; };
C7E5453718EA668700B56C3E /* EFAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C7E5452F18EA668700B56C3E /* EFAppDelegate.m */; };
C7E5453918EA668700B56C3E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C7E5453318EA668700B56C3E /* InfoPlist.strings */; };
C7E5453A18EA668700B56C3E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C7E5453518EA668700B56C3E /* Images.xcassets */; };
C7E5453B18EA668700B56C3E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C7E5453618EA668700B56C3E /* main.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -37,13 +37,6 @@
C70D5E0118DE0AE800E7B749 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
C70D5E0318DE0AE800E7B749 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
C70D5E0518DE0AE800E7B749 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
C70D5E0918DE0AE800E7B749 /* EFMapping-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "EFMapping-Info.plist"; sourceTree = "<group>"; };
C70D5E0B18DE0AE800E7B749 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
C70D5E0D18DE0AE800E7B749 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
C70D5E0F18DE0AE800E7B749 /* EFMapping-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "EFMapping-Prefix.pch"; sourceTree = "<group>"; };
C70D5E1018DE0AE800E7B749 /* EFAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EFAppDelegate.h; sourceTree = "<group>"; };
C70D5E1118DE0AE800E7B749 /* EFAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EFAppDelegate.m; sourceTree = "<group>"; };
C70D5E1318DE0AE800E7B749 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
C70D5E1918DE0AE800E7B749 /* EFMappingTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EFMappingTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C70D5E1A18DE0AE800E7B749 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
C70D5E2218DE0AE900E7B749 /* EFMappingTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "EFMappingTests-Info.plist"; sourceTree = "<group>"; };
Expand All @@ -52,6 +45,13 @@
C70D5E3118DE0B2A00E7B749 /* NSObject+EFMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+EFMapping.m"; sourceTree = "<group>"; };
C70D5E3318DE0B3A00E7B749 /* EFMappingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EFMappingTest.m; sourceTree = "<group>"; };
C778B35918DF32EC00FFB5F2 /* EFMapping.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = EFMapping.podspec; sourceTree = "<group>"; };
C7E5452E18EA668700B56C3E /* EFAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EFAppDelegate.h; sourceTree = "<group>"; };
C7E5452F18EA668700B56C3E /* EFAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EFAppDelegate.m; sourceTree = "<group>"; };
C7E5453018EA668700B56C3E /* EFMapping-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "EFMapping-Info.plist"; sourceTree = "<group>"; };
C7E5453118EA668700B56C3E /* EFMapping-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "EFMapping-Prefix.pch"; sourceTree = "<group>"; };
C7E5453418EA668700B56C3E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = InfoPlist.strings; sourceTree = "<group>"; };
C7E5453518EA668700B56C3E /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
C7E5453618EA668700B56C3E /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -84,6 +84,7 @@
C778B35918DF32EC00FFB5F2 /* EFMapping.podspec */,
C70D5E0718DE0AE800E7B749 /* EFMapping */,
C70D5E2018DE0AE800E7B749 /* EFMappingTests */,
C7E5452D18EA660D00B56C3E /* Test App */,
C70D5E0018DE0AE800E7B749 /* Frameworks */,
C70D5DFF18DE0AE800E7B749 /* Products */,
);
Expand Down Expand Up @@ -114,25 +115,10 @@
children = (
C70D5E3018DE0B2A00E7B749 /* NSObject+EFMapping.h */,
C70D5E3118DE0B2A00E7B749 /* NSObject+EFMapping.m */,
C70D5E1018DE0AE800E7B749 /* EFAppDelegate.h */,
C70D5E1118DE0AE800E7B749 /* EFAppDelegate.m */,
C70D5E1318DE0AE800E7B749 /* Images.xcassets */,
C70D5E0818DE0AE800E7B749 /* Supporting Files */,
);
path = EFMapping;
sourceTree = "<group>";
};
C70D5E0818DE0AE800E7B749 /* Supporting Files */ = {
isa = PBXGroup;
children = (
C70D5E0918DE0AE800E7B749 /* EFMapping-Info.plist */,
C70D5E0A18DE0AE800E7B749 /* InfoPlist.strings */,
C70D5E0D18DE0AE800E7B749 /* main.m */,
C70D5E0F18DE0AE800E7B749 /* EFMapping-Prefix.pch */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
C70D5E2018DE0AE800E7B749 /* EFMappingTests */ = {
isa = PBXGroup;
children = (
Expand All @@ -151,6 +137,36 @@
name = "Supporting Files";
sourceTree = "<group>";
};
C7E5452D18EA660D00B56C3E /* Test App */ = {
isa = PBXGroup;
children = (
C7E5452E18EA668700B56C3E /* EFAppDelegate.h */,
C7E5452F18EA668700B56C3E /* EFAppDelegate.m */,
C7E5453C18EA66B600B56C3E /* Supporting Files */,
);
path = "Test App";
sourceTree = "<group>";
};
C7E5453218EA668700B56C3E /* en.lproj */ = {
isa = PBXGroup;
children = (
C7E5453318EA668700B56C3E /* InfoPlist.strings */,
);
path = en.lproj;
sourceTree = "<group>";
};
C7E5453C18EA66B600B56C3E /* Supporting Files */ = {
isa = PBXGroup;
children = (
C7E5453118EA668700B56C3E /* EFMapping-Prefix.pch */,
C7E5453618EA668700B56C3E /* main.m */,
C7E5453018EA668700B56C3E /* EFMapping-Info.plist */,
C7E5453218EA668700B56C3E /* en.lproj */,
C7E5453518EA668700B56C3E /* Images.xcassets */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -227,8 +243,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C70D5E0C18DE0AE800E7B749 /* InfoPlist.strings in Resources */,
C70D5E1418DE0AE800E7B749 /* Images.xcassets in Resources */,
C7E5453A18EA668700B56C3E /* Images.xcassets in Resources */,
C7E5453918EA668700B56C3E /* InfoPlist.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -247,9 +263,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C70D5E0E18DE0AE800E7B749 /* main.m in Sources */,
C7E5453B18EA668700B56C3E /* main.m in Sources */,
C7E5453718EA668700B56C3E /* EFAppDelegate.m in Sources */,
C70D5E3218DE0B2A00E7B749 /* NSObject+EFMapping.m in Sources */,
C70D5E1218DE0AE800E7B749 /* EFAppDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -272,18 +288,18 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
C70D5E0A18DE0AE800E7B749 /* InfoPlist.strings */ = {
C70D5E2318DE0AE900E7B749 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
C70D5E0B18DE0AE800E7B749 /* en */,
C70D5E2418DE0AE900E7B749 /* en */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
C70D5E2318DE0AE900E7B749 /* InfoPlist.strings */ = {
C7E5453318EA668700B56C3E /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
C70D5E2418DE0AE900E7B749 /* en */,
C7E5453418EA668700B56C3E /* en */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
Expand Down Expand Up @@ -369,8 +385,8 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "EFMapping/EFMapping-Prefix.pch";
INFOPLIST_FILE = "EFMapping/EFMapping-Info.plist";
GCC_PREFIX_HEADER = "Test App/EFMapping-Prefix.pch";
INFOPLIST_FILE = "Test App/EFMapping-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -382,8 +398,8 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "EFMapping/EFMapping-Prefix.pch";
INFOPLIST_FILE = "EFMapping/EFMapping-Info.plist";
GCC_PREFIX_HEADER = "Test App/EFMapping-Prefix.pch";
INFOPLIST_FILE = "Test App/EFMapping-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -399,7 +415,7 @@
"$(DEVELOPER_FRAMEWORKS_DIR)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "EFMapping/EFMapping-Prefix.pch";
GCC_PREFIX_HEADER = "Test App/EFMapping-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -421,7 +437,7 @@
"$(DEVELOPER_FRAMEWORKS_DIR)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "EFMapping/EFMapping-Prefix.pch";
GCC_PREFIX_HEADER = "Test App/EFMapping-Prefix.pch";
INFOPLIST_FILE = "EFMappingTests/EFMappingTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
Expand Down
37 changes: 37 additions & 0 deletions EFMapping/NSObject+EFMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,40 @@ - (id)dictionaryRepresentationForKeys:(NSArray *)keys {
}

@end

@implementation NSArray (EFMapping)

- (id)dictionaryRepresentationForKeys:(NSArray *)keys {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self count]];
for (id object in self) {
id representation = [object dictionaryRepresentation];
if (representation) {
[array addObject:representation];
} else {
[array addObject:[NSNull null]];
}
}
return [array copy];
}

@end

@implementation NSDictionary (EFMapping)

- (id)dictionaryRepresentationForKeys:(NSArray *)keys {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:[self count]];
[self enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
id keyRepresentation = [key dictionaryRepresentation];
if (keyRepresentation) {
id representation = [object dictionaryRepresentation];
if (representation) {
dictionary[keyRepresentation] = representation;
} else {
dictionary[keyRepresentation] = [NSNull null];
};
}
}];
return [dictionary copy];
}

@end
19 changes: 15 additions & 4 deletions EFMappingTests/EFMappingTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ @implementation EFSample

+ (NSArray *)mappings {
static NSArray *mappings = nil;
NSDateFormatter *dateFormatter = nil;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
if (!mappings) {
mappings = @[[EFMapping mappingForClass:[NSString class] externalKey:@"id" internalKey:@"guid"],
[EFMapping mappingForNumberWithExternalKey:@"pts_mine" internalKey:@"myPoints"],
[EFMapping mappingForClass:[NSDate class] externalKey:@"created_at" internalKey:@"creationDate" formatter:dateFormatter],
[EFMapping mappingForClass:[EFSample class] key:@"sample"],
[EFMapping mappingArrayOfClass:[EFSample class] externalKey:@"related_samples" internalKey:@"relatedSamples"]
[EFMapping mappingForArrayOfClass:[EFSample class] externalKey:@"related_samples" internalKey:@"relatedSamples"]
];
}
return mappings;
Expand Down Expand Up @@ -69,14 +70,14 @@ - (void)setUp {
_sample2 = [[EFSample alloc] init];
_validDictionary = @{@"id": @"1",
@"pts_mine": @10,
@"created_at": [NSDate date],
@"created_at": @"2014-04-01",
@"sample": @{@"id": @"2", @"pts_mine": @20},
@"related_samples": @[@{@"id": @"3", @"pts_mine": @30},
@{@"id": @"4", @"pts_mine": @40}],
@"unknown_key": @"foobarbaz"};
_invalidDictionary = @{@"id": @1,
@"pts_mine": @10,
@"created_at": [NSDate date],
@"created_at": @"2014-04-01",
@"sample": @{@"id": @"2", @"pts_mine": @20},
@"related_samples": @[@{@"id": @"3", @"pts_mine": @30},
@{@"id": @4, @"pts_mine": @40}]};
Expand Down Expand Up @@ -112,7 +113,17 @@ - (void)testSettingValues {
}

- (void)testTransformingValues {
NSError *error = nil;
BOOL valid1 = [_sample1 setValues:_validDictionary error:&error];

XCTAssertTrue(valid1, @"Expected values to be valid but found error %@", error);

XCTAssertTrue([_sample1.creationDate isKindOfClass:[NSDate class]], @"Expected a date");

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:_sample1.creationDate];
XCTAssertEqual(components.year, 2014, @"Expected year 2014");
XCTAssertEqual(components.month, 4, @"Expected month 4");
XCTAssertEqual(components.day, 1, @"Expected day 1");
}

- (void)testEncoding {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3791eff

Please sign in to comment.