From 0f74776f5ba86821c432601e3307482e4989c05b Mon Sep 17 00:00:00 2001 From: Tristan Himmelman Date: Thu, 30 Apr 2015 17:20:35 -0400 Subject: [PATCH] - added gitignore - created Alamofire Request extension - added some tests - added iOS and OS X targets --- .gitignore | 2 +- AlamofireObjectMapper.podspec | 18 + .../project.pbxproj | 691 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../AlamofireObjectMapper OSX.xcscheme | 110 +++ .../AlamofireObjectMapper iOS.xcscheme | 96 +++ .../contents.xcworkspacedata | 13 + AlamofireObjectMapper/AlamofireObjectMapper.h | 19 + .../AlmofireObjectMapper.swift | 70 ++ AlamofireObjectMapper/Info.plist | 26 + .../AlamofireObjectMapperTests.swift | 113 +++ AlamofireObjectMapperTests/Info.plist | 24 + Cartfile.private | 2 + Cartfile.resolved | 2 + README.md | 79 ++ 15 files changed, 1271 insertions(+), 1 deletion(-) create mode 100644 AlamofireObjectMapper.podspec create mode 100644 AlamofireObjectMapper.xcodeproj/project.pbxproj create mode 100644 AlamofireObjectMapper.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper OSX.xcscheme create mode 100644 AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper iOS.xcscheme create mode 100644 AlamofireObjectMapper.xcworkspace/contents.xcworkspacedata create mode 100644 AlamofireObjectMapper/AlamofireObjectMapper.h create mode 100644 AlamofireObjectMapper/AlmofireObjectMapper.swift create mode 100644 AlamofireObjectMapper/Info.plist create mode 100644 AlamofireObjectMapperTests/AlamofireObjectMapperTests.swift create mode 100644 AlamofireObjectMapperTests/Info.plist create mode 100644 Cartfile.private create mode 100644 Cartfile.resolved create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 8615121..60089aa 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,6 @@ DerivedData # Carthage # # Add this line if you want to avoid checking in source code from Carthage dependencies. -# Carthage/Checkouts +Carthage/Checkouts Carthage/Build diff --git a/AlamofireObjectMapper.podspec b/AlamofireObjectMapper.podspec new file mode 100644 index 0000000..58a27cb --- /dev/null +++ b/AlamofireObjectMapper.podspec @@ -0,0 +1,18 @@ +Pod::Spec.new do |s| + + s.name = "AlamofireObjectMapper" + s.version = "0.1" + s.license = { :type => "MIT", :file => "LICENSE" } + s.summary = "An extension to Alamofire which converts responses into objects using ObjectMapper" + s.homepage = "https://github.com/tristanhimmelman/AlamofireObjectMapper" + s.author = { "Tristan Himmelman" => "tristanhimmelman@gmail.com" } + s.source = { :git => 'https://github.com/tristanhimmelman/AlamofireObjectMapper.git', :tag => s.version.to_s } + + s.ios.deployment_target = '8.0' + s.osx.deployment_target = '10.9' + s.requires_arc = 'true' + s.source_files = 'AlamofireObjectMapper/**/*.swift' + s.dependency 'Alamofire', '~> 1.2' + s.dependency 'ObjectMapper', '~> 0.10' + +end \ No newline at end of file diff --git a/AlamofireObjectMapper.xcodeproj/project.pbxproj b/AlamofireObjectMapper.xcodeproj/project.pbxproj new file mode 100644 index 0000000..8a8aedd --- /dev/null +++ b/AlamofireObjectMapper.xcodeproj/project.pbxproj @@ -0,0 +1,691 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 6AB2A0171AF26C36001EBB20 /* AlamofireObjectMapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 6AB2A0161AF26C36001EBB20 /* AlamofireObjectMapper.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6AB2A01D1AF26C36001EBB20 /* AlamofireObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A0111AF26C36001EBB20 /* AlamofireObjectMapper.framework */; }; + 6AB2A0241AF26C36001EBB20 /* AlamofireObjectMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AB2A0231AF26C36001EBB20 /* AlamofireObjectMapperTests.swift */; }; + 6AB2A02E1AF2746D001EBB20 /* AlmofireObjectMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AB2A02D1AF2746D001EBB20 /* AlmofireObjectMapper.swift */; }; + 6AB2A0901AF27DF1001EBB20 /* AlamofireObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A0851AF27DF1001EBB20 /* AlamofireObjectMapper.framework */; }; + 6AB2A09E1AF27E6A001EBB20 /* AlamofireObjectMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AB2A0231AF26C36001EBB20 /* AlamofireObjectMapperTests.swift */; }; + 6AB2A0A01AF28166001EBB20 /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A09F1AF28166001EBB20 /* ObjectMapper.framework */; }; + 6AB2A0A21AF2816E001EBB20 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A0A11AF2816E001EBB20 /* Alamofire.framework */; }; + 6AB2A0A31AF28176001EBB20 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A0A11AF2816E001EBB20 /* Alamofire.framework */; }; + 6AB2A0A41AF28176001EBB20 /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A09F1AF28166001EBB20 /* ObjectMapper.framework */; }; + 6AB2A0A51AF282A6001EBB20 /* AlmofireObjectMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AB2A02D1AF2746D001EBB20 /* AlmofireObjectMapper.swift */; }; + 6AB2A0AC1AF283B2001EBB20 /* Alamofire.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A0A11AF2816E001EBB20 /* Alamofire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 6AB2A0AD1AF283B2001EBB20 /* ObjectMapper.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A09F1AF28166001EBB20 /* ObjectMapper.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 6AB2A0AF1AF283C8001EBB20 /* Alamofire.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A0A11AF2816E001EBB20 /* Alamofire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 6AB2A0B01AF283C8001EBB20 /* ObjectMapper.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB2A09F1AF28166001EBB20 /* ObjectMapper.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 6AB2A01E1AF26C36001EBB20 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 6AB2A0081AF26C36001EBB20 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 6AB2A0101AF26C36001EBB20; + remoteInfo = AlamofireObjectMapper; + }; + 6AB2A0911AF27DF1001EBB20 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 6AB2A0081AF26C36001EBB20 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 6AB2A0841AF27DF1001EBB20; + remoteInfo = "AlamofireObjectMapper OSX"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 6AB2A0AB1AF283A5001EBB20 /* Copy Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 8; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 6AB2A0AC1AF283B2001EBB20 /* Alamofire.framework in Copy Frameworks */, + 6AB2A0AD1AF283B2001EBB20 /* ObjectMapper.framework in Copy Frameworks */, + ); + name = "Copy Frameworks"; + runOnlyForDeploymentPostprocessing = 1; + }; + 6AB2A0AE1AF283C0001EBB20 /* Copy Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 8; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 6AB2A0AF1AF283C8001EBB20 /* Alamofire.framework in Copy Frameworks */, + 6AB2A0B01AF283C8001EBB20 /* ObjectMapper.framework in Copy Frameworks */, + ); + name = "Copy Frameworks"; + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 6AB2A0111AF26C36001EBB20 /* AlamofireObjectMapper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AlamofireObjectMapper.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6AB2A0151AF26C36001EBB20 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 6AB2A0161AF26C36001EBB20 /* AlamofireObjectMapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AlamofireObjectMapper.h; sourceTree = ""; }; + 6AB2A01C1AF26C36001EBB20 /* AlamofireObjectMapperTests iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "AlamofireObjectMapperTests iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 6AB2A0221AF26C36001EBB20 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 6AB2A0231AF26C36001EBB20 /* AlamofireObjectMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlamofireObjectMapperTests.swift; sourceTree = ""; }; + 6AB2A02D1AF2746D001EBB20 /* AlmofireObjectMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlmofireObjectMapper.swift; sourceTree = ""; }; + 6AB2A0851AF27DF1001EBB20 /* AlamofireObjectMapper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AlamofireObjectMapper.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 6AB2A08F1AF27DF1001EBB20 /* AlamofireObjectMapperTests OSX.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "AlamofireObjectMapperTests OSX.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 6AB2A09F1AF28166001EBB20 /* ObjectMapper.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectMapper.framework; path = "../../../../../Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos/ObjectMapper.framework"; sourceTree = ""; }; + 6AB2A0A11AF2816E001EBB20 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = "../../../../../Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos/Alamofire.framework"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 6AB2A00D1AF26C36001EBB20 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A0191AF26C36001EBB20 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AB2A0A21AF2816E001EBB20 /* Alamofire.framework in Frameworks */, + 6AB2A0A01AF28166001EBB20 /* ObjectMapper.framework in Frameworks */, + 6AB2A01D1AF26C36001EBB20 /* AlamofireObjectMapper.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A0811AF27DF1001EBB20 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A08C1AF27DF1001EBB20 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AB2A0A31AF28176001EBB20 /* Alamofire.framework in Frameworks */, + 6AB2A0A41AF28176001EBB20 /* ObjectMapper.framework in Frameworks */, + 6AB2A0901AF27DF1001EBB20 /* AlamofireObjectMapper.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 6AB2A0071AF26C36001EBB20 = { + isa = PBXGroup; + children = ( + 6AB2A0131AF26C36001EBB20 /* AlamofireObjectMapper */, + 6AB2A0201AF26C36001EBB20 /* AlamofireObjectMapperTests */, + 6AB2A0121AF26C36001EBB20 /* Products */, + ); + sourceTree = ""; + }; + 6AB2A0121AF26C36001EBB20 /* Products */ = { + isa = PBXGroup; + children = ( + 6AB2A0111AF26C36001EBB20 /* AlamofireObjectMapper.framework */, + 6AB2A01C1AF26C36001EBB20 /* AlamofireObjectMapperTests iOS.xctest */, + 6AB2A0851AF27DF1001EBB20 /* AlamofireObjectMapper.framework */, + 6AB2A08F1AF27DF1001EBB20 /* AlamofireObjectMapperTests OSX.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 6AB2A0131AF26C36001EBB20 /* AlamofireObjectMapper */ = { + isa = PBXGroup; + children = ( + 6AB2A0161AF26C36001EBB20 /* AlamofireObjectMapper.h */, + 6AB2A02D1AF2746D001EBB20 /* AlmofireObjectMapper.swift */, + 6AB2A0141AF26C36001EBB20 /* Supporting Files */, + ); + path = AlamofireObjectMapper; + sourceTree = ""; + }; + 6AB2A0141AF26C36001EBB20 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 6AB2A0A11AF2816E001EBB20 /* Alamofire.framework */, + 6AB2A09F1AF28166001EBB20 /* ObjectMapper.framework */, + 6AB2A0151AF26C36001EBB20 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 6AB2A0201AF26C36001EBB20 /* AlamofireObjectMapperTests */ = { + isa = PBXGroup; + children = ( + 6AB2A0231AF26C36001EBB20 /* AlamofireObjectMapperTests.swift */, + 6AB2A0211AF26C36001EBB20 /* Supporting Files */, + ); + path = AlamofireObjectMapperTests; + sourceTree = ""; + }; + 6AB2A0211AF26C36001EBB20 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 6AB2A0221AF26C36001EBB20 /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 6AB2A00E1AF26C36001EBB20 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AB2A0171AF26C36001EBB20 /* AlamofireObjectMapper.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A0821AF27DF1001EBB20 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 6AB2A0101AF26C36001EBB20 /* AlamofireObjectMapper iOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6AB2A0271AF26C36001EBB20 /* Build configuration list for PBXNativeTarget "AlamofireObjectMapper iOS" */; + buildPhases = ( + 6AB2A00C1AF26C36001EBB20 /* Sources */, + 6AB2A00D1AF26C36001EBB20 /* Frameworks */, + 6AB2A00E1AF26C36001EBB20 /* Headers */, + 6AB2A0AB1AF283A5001EBB20 /* Copy Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "AlamofireObjectMapper iOS"; + productName = AlamofireObjectMapper; + productReference = 6AB2A0111AF26C36001EBB20 /* AlamofireObjectMapper.framework */; + productType = "com.apple.product-type.framework"; + }; + 6AB2A01B1AF26C36001EBB20 /* AlamofireObjectMapperTests iOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6AB2A02A1AF26C36001EBB20 /* Build configuration list for PBXNativeTarget "AlamofireObjectMapperTests iOS" */; + buildPhases = ( + 6AB2A0181AF26C36001EBB20 /* Sources */, + 6AB2A0191AF26C36001EBB20 /* Frameworks */, + 6AB2A01A1AF26C36001EBB20 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 6AB2A01F1AF26C36001EBB20 /* PBXTargetDependency */, + ); + name = "AlamofireObjectMapperTests iOS"; + productName = AlamofireObjectMapperTests; + productReference = 6AB2A01C1AF26C36001EBB20 /* AlamofireObjectMapperTests iOS.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 6AB2A0841AF27DF1001EBB20 /* AlamofireObjectMapper OSX */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6AB2A0981AF27DF1001EBB20 /* Build configuration list for PBXNativeTarget "AlamofireObjectMapper OSX" */; + buildPhases = ( + 6AB2A0801AF27DF1001EBB20 /* Sources */, + 6AB2A0811AF27DF1001EBB20 /* Frameworks */, + 6AB2A0821AF27DF1001EBB20 /* Headers */, + 6AB2A0831AF27DF1001EBB20 /* Resources */, + 6AB2A0AE1AF283C0001EBB20 /* Copy Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "AlamofireObjectMapper OSX"; + productName = "AlamofireObjectMapper OSX"; + productReference = 6AB2A0851AF27DF1001EBB20 /* AlamofireObjectMapper.framework */; + productType = "com.apple.product-type.framework"; + }; + 6AB2A08E1AF27DF1001EBB20 /* AlamofireObjectMapperTests OSX */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6AB2A09B1AF27DF1001EBB20 /* Build configuration list for PBXNativeTarget "AlamofireObjectMapperTests OSX" */; + buildPhases = ( + 6AB2A08B1AF27DF1001EBB20 /* Sources */, + 6AB2A08C1AF27DF1001EBB20 /* Frameworks */, + 6AB2A08D1AF27DF1001EBB20 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 6AB2A0921AF27DF1001EBB20 /* PBXTargetDependency */, + ); + name = "AlamofireObjectMapperTests OSX"; + productName = "AlamofireObjectMapper OSXTests"; + productReference = 6AB2A08F1AF27DF1001EBB20 /* AlamofireObjectMapperTests OSX.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 6AB2A0081AF26C36001EBB20 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0630; + ORGANIZATIONNAME = "Tristan Himmelman"; + TargetAttributes = { + 6AB2A0101AF26C36001EBB20 = { + CreatedOnToolsVersion = 6.3.1; + }; + 6AB2A01B1AF26C36001EBB20 = { + CreatedOnToolsVersion = 6.3.1; + }; + 6AB2A0841AF27DF1001EBB20 = { + CreatedOnToolsVersion = 6.3.1; + }; + 6AB2A08E1AF27DF1001EBB20 = { + CreatedOnToolsVersion = 6.3.1; + }; + }; + }; + buildConfigurationList = 6AB2A00B1AF26C36001EBB20 /* Build configuration list for PBXProject "AlamofireObjectMapper" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 6AB2A0071AF26C36001EBB20; + productRefGroup = 6AB2A0121AF26C36001EBB20 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6AB2A0101AF26C36001EBB20 /* AlamofireObjectMapper iOS */, + 6AB2A0841AF27DF1001EBB20 /* AlamofireObjectMapper OSX */, + 6AB2A01B1AF26C36001EBB20 /* AlamofireObjectMapperTests iOS */, + 6AB2A08E1AF27DF1001EBB20 /* AlamofireObjectMapperTests OSX */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 6AB2A01A1AF26C36001EBB20 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A0831AF27DF1001EBB20 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A08D1AF27DF1001EBB20 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 6AB2A00C1AF26C36001EBB20 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AB2A02E1AF2746D001EBB20 /* AlmofireObjectMapper.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A0181AF26C36001EBB20 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AB2A0241AF26C36001EBB20 /* AlamofireObjectMapperTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A0801AF27DF1001EBB20 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AB2A0A51AF282A6001EBB20 /* AlmofireObjectMapper.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 6AB2A08B1AF27DF1001EBB20 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AB2A09E1AF27E6A001EBB20 /* AlamofireObjectMapperTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 6AB2A01F1AF26C36001EBB20 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 6AB2A0101AF26C36001EBB20 /* AlamofireObjectMapper iOS */; + targetProxy = 6AB2A01E1AF26C36001EBB20 /* PBXContainerItemProxy */; + }; + 6AB2A0921AF27DF1001EBB20 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 6AB2A0841AF27DF1001EBB20 /* AlamofireObjectMapper OSX */; + targetProxy = 6AB2A0911AF27DF1001EBB20 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 6AB2A0251AF26C36001EBB20 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 6AB2A0261AF26C36001EBB20 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 6AB2A0281AF26C36001EBB20 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = NO; + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Checkouts/Alamofire/build/Debug-iphoneos", + "$(PROJECT_DIR)/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos", + ); + INFOPLIST_FILE = AlamofireObjectMapper/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = AlamofireObjectMapper; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 6AB2A0291AF26C36001EBB20 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = NO; + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Checkouts/Alamofire/build/Debug-iphoneos", + "$(PROJECT_DIR)/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos", + ); + INFOPLIST_FILE = AlamofireObjectMapper/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = AlamofireObjectMapper; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 6AB2A02B1AF26C36001EBB20 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = AlamofireObjectMapperTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 6AB2A02C1AF26C36001EBB20 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos", + ); + INFOPLIST_FILE = AlamofireObjectMapperTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 6AB2A0991AF27DF1001EBB20 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = AlamofireObjectMapper/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_NAME = AlamofireObjectMapper; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 6AB2A09A1AF27DF1001EBB20 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = AlamofireObjectMapper/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_NAME = AlamofireObjectMapper; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 6AB2A09C1AF27DF1001EBB20 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = AlamofireObjectMapperTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Debug; + }; + 6AB2A09D1AF27DF1001EBB20 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos", + ); + INFOPLIST_FILE = AlamofireObjectMapperTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 6AB2A00B1AF26C36001EBB20 /* Build configuration list for PBXProject "AlamofireObjectMapper" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6AB2A0251AF26C36001EBB20 /* Debug */, + 6AB2A0261AF26C36001EBB20 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6AB2A0271AF26C36001EBB20 /* Build configuration list for PBXNativeTarget "AlamofireObjectMapper iOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6AB2A0281AF26C36001EBB20 /* Debug */, + 6AB2A0291AF26C36001EBB20 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6AB2A02A1AF26C36001EBB20 /* Build configuration list for PBXNativeTarget "AlamofireObjectMapperTests iOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6AB2A02B1AF26C36001EBB20 /* Debug */, + 6AB2A02C1AF26C36001EBB20 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6AB2A0981AF27DF1001EBB20 /* Build configuration list for PBXNativeTarget "AlamofireObjectMapper OSX" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6AB2A0991AF27DF1001EBB20 /* Debug */, + 6AB2A09A1AF27DF1001EBB20 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6AB2A09B1AF27DF1001EBB20 /* Build configuration list for PBXNativeTarget "AlamofireObjectMapperTests OSX" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6AB2A09C1AF27DF1001EBB20 /* Debug */, + 6AB2A09D1AF27DF1001EBB20 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 6AB2A0081AF26C36001EBB20 /* Project object */; +} diff --git a/AlamofireObjectMapper.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/AlamofireObjectMapper.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..aeeaadc --- /dev/null +++ b/AlamofireObjectMapper.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper OSX.xcscheme b/AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper OSX.xcscheme new file mode 100644 index 0000000..9fbad40 --- /dev/null +++ b/AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper OSX.xcscheme @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper iOS.xcscheme b/AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper iOS.xcscheme new file mode 100644 index 0000000..8248808 --- /dev/null +++ b/AlamofireObjectMapper.xcodeproj/xcshareddata/xcschemes/AlamofireObjectMapper iOS.xcscheme @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AlamofireObjectMapper.xcworkspace/contents.xcworkspacedata b/AlamofireObjectMapper.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..8b95fc7 --- /dev/null +++ b/AlamofireObjectMapper.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/AlamofireObjectMapper/AlamofireObjectMapper.h b/AlamofireObjectMapper/AlamofireObjectMapper.h new file mode 100644 index 0000000..8a45ce5 --- /dev/null +++ b/AlamofireObjectMapper/AlamofireObjectMapper.h @@ -0,0 +1,19 @@ +// +// AlamofireObjectMapper.h +// AlamofireObjectMapper +// +// Created by Tristan Himmelman on 2015-04-30. +// Copyright (c) 2015 Tristan Himmelman. All rights reserved. +// + +#import + +//! Project version number for AlamofireObjectMapper. +FOUNDATION_EXPORT double AlamofireObjectMapperVersionNumber; + +//! Project version string for AlamofireObjectMapper. +FOUNDATION_EXPORT const unsigned char AlamofireObjectMapperVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/AlamofireObjectMapper/AlmofireObjectMapper.swift b/AlamofireObjectMapper/AlmofireObjectMapper.swift new file mode 100644 index 0000000..bf9a861 --- /dev/null +++ b/AlamofireObjectMapper/AlmofireObjectMapper.swift @@ -0,0 +1,70 @@ +// +// Request.swift +// AlamofireObjectMapper +// +// Created by Tristan Himmelman on 2015-04-30. +// Copyright (c) 2015 Tristan Himmelman. All rights reserved. +// + +import Foundation +import Alamofire +import ObjectMapper + +extension Request { + + /** + Adds a handler to be called once the request has finished. + + :param: completionHandler A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 2 arguments: the response object (of type Mappable) and any error produced while making the request + + :returns: The request. + */ + public func responseObject(completionHandler: (T?, NSError?) -> Void) -> Self { + return response(queue: nil, serializer: Request.JSONResponseSerializer(options: NSJSONReadingOptions.AllowFragments)) { (request, response, object, error) -> Void in + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { + + let parsedObject = Mapper().map(object) + + dispatch_async(dispatch_get_main_queue()) { + completionHandler(parsedObject, error) + } + } + } + } + + /** + Adds a handler to be called once the request has finished. + + :param: completionHandler A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 5 arguments: the URL request, the URL response, the response object (of type Mappable), the raw response data, and any error produced making the request. + + :returns: The request. + */ + public func responseObject(completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, NSError?) -> Void) -> Self { + return responseObject(nil, completionHandler: completionHandler) + } + + /** + Adds a handler to be called once the request has finished. + + :param: queue The queue on which the completion handler is dispatched. + :param: completionHandler A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 5 arguments: the URL request, the URL response, the response object (of type Mappable), the raw response data, and any error produced making the request. + + :returns: The request. + */ + public func responseObject(queue: dispatch_queue_t?, completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, NSError?) -> Void) -> Self { + + return response(queue: queue, serializer: Request.JSONResponseSerializer(options: NSJSONReadingOptions.AllowFragments)) { (request, response, data, error) -> Void in + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { + + let parsedObject = Mapper().map(data) + + dispatch_async(queue ?? dispatch_get_main_queue()) { + completionHandler(self.request, self.response, parsedObject, data, error) + } + } + } + + } +} \ No newline at end of file diff --git a/AlamofireObjectMapper/Info.plist b/AlamofireObjectMapper/Info.plist new file mode 100644 index 0000000..ad8b48c --- /dev/null +++ b/AlamofireObjectMapper/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.tristanhimmelman.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/AlamofireObjectMapperTests/AlamofireObjectMapperTests.swift b/AlamofireObjectMapperTests/AlamofireObjectMapperTests.swift new file mode 100644 index 0000000..3065530 --- /dev/null +++ b/AlamofireObjectMapperTests/AlamofireObjectMapperTests.swift @@ -0,0 +1,113 @@ +// +// AlamofireObjectMapperTests.swift +// AlamofireObjectMapperTests +// +// Created by Tristan Himmelman on 2015-04-30. +// Copyright (c) 2015 Tristan Himmelman. All rights reserved. +// + +import Foundation +import XCTest +import ObjectMapper +import Alamofire +import AlamofireObjectMapper + +class AlamofireObjectMapperTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testResponseObject() { + // This is an example of a functional test case. + + let URL = "http://httpbin.org/get" + let parameters = ["param1": "hello", "param2": "goodbye"] + let expectation = expectationWithDescription("\(URL)") + + Alamofire.request(.GET, URL, parameters: parameters).responseObject { (response: Response?, error: NSError?) in + expectation.fulfill() + + XCTAssertNotNil(response, "Response should not be nil") + XCTAssertNotNil(response?.arguments, "Arguents should not be nil") + XCTAssertEqual(response!.arguments!, parameters, "Arguments should equal parameters that were passed into request") + XCTAssertNotNil(response?.origin, "Origin should not be nil") + XCTAssertNotNil(response?.url, "URL should not be nil") + XCTAssertNotNil(response?.header, "Header should not be nil") + XCTAssertNotNil(response?.header?.host, "Host should not be nil") + XCTAssertNotNil(response?.header?.userAgent, "User Agent should not be nil") + } + + waitForExpectationsWithTimeout(10, handler: { (error: NSError!) -> Void in + XCTAssertNil(error, "\(error)") + }) + } + + func testResponseObject2() { + // This is an example of a functional test case. + + let URL = "http://httpbin.org/get" + let parameters = ["param1":"hello", "param2": "goodbye"] + let expectation = expectationWithDescription("\(URL)") + + Alamofire.request(.GET, URL, parameters: parameters).responseObject { (request: NSURLRequest, HTTPURLResponse: NSHTTPURLResponse?, response: Response?, data: AnyObject?, error: NSError?) in + + expectation.fulfill() + + XCTAssertNotNil(response, "Response should not be nil") + XCTAssertNotNil(response?.arguments, "Arguents should not be nil") + XCTAssertEqual(response!.arguments!, parameters, "Arguments should equal parameters that were passed into request") + XCTAssertNotNil(response?.origin, "Origin should not be nil") + XCTAssertNotNil(response?.url, "URL should not be nil") + XCTAssertNotNil(response?.header, "Header should not be nil") + XCTAssertNotNil(response?.header?.host, "Host should not be nil") + XCTAssertNotNil(response?.header?.userAgent, "User Agent should not be nil") + } + + waitForExpectationsWithTimeout(10, handler: { (error: NSError!) -> Void in + XCTAssertNil(error, "\(error)") + }) + } +} + +class Response: Mappable { + var header: Header? + var origin: String? + var url: NSURL? + var arguments: [String:String]? + + init() {} + + required init?(_ map: Map) { + mapping(map) + } + + func mapping(map: Map) { + header <- map["headers"] + origin <- map["origin"] + url <- (map["url"], URLTransform()) + arguments <- map["args"] + } +} + +class Header: Mappable { + var host: String? + var userAgent: String? + + init() {} + + required init?(_ map: Map) { + mapping(map) + } + + func mapping(map: Map) { + host <- map["Host"] + userAgent <- map["User-Agent"] + } +} diff --git a/AlamofireObjectMapperTests/Info.plist b/AlamofireObjectMapperTests/Info.plist new file mode 100644 index 0000000..27af007 --- /dev/null +++ b/AlamofireObjectMapperTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.tristanhimmelman.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/Cartfile.private b/Cartfile.private new file mode 100644 index 0000000..7a6b031 --- /dev/null +++ b/Cartfile.private @@ -0,0 +1,2 @@ +github "Alamofire/Alamofire" >= 1.2 +github "Hearst-DD/ObjectMapper" >= 0.10 diff --git a/Cartfile.resolved b/Cartfile.resolved new file mode 100644 index 0000000..db45da7 --- /dev/null +++ b/Cartfile.resolved @@ -0,0 +1,2 @@ +github "Alamofire/Alamofire" "1.2.1" +github "Hearst-DD/ObjectMapper" "0.10" diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2c5752 --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +AlamofireObjectMapper +============ + +An extension to [Alamofire](https://github.com/Alamofire/Alamofire) which automatically converts response data into swift objects using [ObjectMapper](https://github.com/Hearst-DD/ObjectMapper/). + +#Usage + +Given a URL which returns weather data in the following form: +``` +{ + "location": "Toronto, Canada", + "conditions": "Partly cloudy", + "temperature": 20 + "forecast": { + "1pm" : 21, + "2pm" : 22, + "3pm" : 23 + } +} +``` + +You can use this extension as the follows: +```swift +let URL = "http://weather.com/toronto" +Alamofire.request(.GET, URL, parameters: nil).responseObject { (response: WeatherResponse?, error: NSError?) in + println(response?.conditions) + println(response?.temperature) + println(response?.forecast?["3pm"]) +} +``` + +The `WeatherResponse` object in the completion handler is a custom object which you define. The only requirement is that the object must conform to [ObjectMapper's](https://github.com/Hearst-DD/ObjectMapper/) `Mappable` protocol. In the above example, the `WeatherResponse` object looks like the following: + +```swift +class WeatherResponse: Mappable { + var location: String? + var conditions: String? + var temperature: Int? + var forecast: [String:Int]? + + init() {} + + required init?(_ map: Map) { + mapping(map) + } + + func mapping(map: Map) { + location <- map["location"] + conditions <- map["conditions"] + temperature <- map["temperature"] + forecast <- map["forecast"] + } +} +``` + +The extension uses Generics to allow you to create your own custom response objects. Below are the three functions which you can use to have your responses mapped to objects. Just replace `T` with your custom response object and the extension handles the rest: + +```swift +func responseObject(completionHandler: (T?, NSError?) -> Void) -> Self +``` + +```swift +func responseObject(completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, NSError?) -> Void) -> Self +``` + +```swift +func responseObject(queue: dispatch_queue_t?, completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, NSError?) -> Void) -> Self +``` + +#Installation +AlamofireObjectMapper can be added to your project using [Cocoapods](https://cocoapods.org/) by adding the following line to your Podfile: +``` +pod 'AlamofireObjectMapper', '~> 0.1' +``` + +If your using [Carthage](https://github.com/Carthage/Carthage) you can add a dependency on AlamofireObjectMapper by adding it to your Cartfile: +``` +github "tristanhimmelman/AlamofireObjectMapper" ~> 0.1 +``` \ No newline at end of file