Git Product home page Git Product logo

alamofireobjectmapper's Introduction

AlamofireObjectMapper

Build Status CocoaPods Carthage compatible

An extension to Alamofire which automatically converts JSON response data into swift objects using ObjectMapper.

Usage

Given a URL which returns weather data in the following form:

{
    "location": "Toronto, Canada",    
    "three_day_forecast": [
        { 
            "conditions": "Partly cloudy",
            "day" : "Monday",
            "temperature": 20 
        },
        { 
            "conditions": "Showers",
            "day" : "Tuesday",
            "temperature": 22 
        },
        { 
            "conditions": "Sunny",
            "day" : "Wednesday",
            "temperature": 28 
        }
    ]
}

You can use the extension as the follows:

import AlamofireObjectMapper

let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/d8bb95982be8a11a2308e779bb9a9707ebe42ede/sample_json"
Alamofire.request(URL).responseObject { (response: DataResponse<WeatherResponse>) in

    let weatherResponse = response.result.value
    print(weatherResponse?.location)
    
    if let threeDayForecast = weatherResponse?.threeDayForecast {
        for forecast in threeDayForecast {
            print(forecast.day)
            print(forecast.temperature)           
        }
    }
}

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 Mappable protocol. In the above example, the WeatherResponse object looks like the following:

import ObjectMapper

class WeatherResponse: Mappable {
    var location: String?
    var threeDayForecast: [Forecast]?
    
	required init?(map: Map){

	}
    
    func mapping(map: Map) {
        location <- map["location"]
        threeDayForecast <- map["three_day_forecast"]
    }
}

class Forecast: Mappable {
    var day: String?
    var temperature: Int?
    var conditions: String?
    
	required init?(map: Map){

	}
    
    func mapping(map: Map) {
        day <- map["day"]
        temperature <- map["temperature"]
        conditions <- map["conditions"]
    }
}

The extension uses Generics to allow you to create your own custom response objects. Below is the responseObject function definition. Just replace T in the completionHandler with your custom response object and the extension handles the rest:

public func responseObject<T: BaseMappable>(queue: DispatchQueue? = nil, keyPath: String? = nil, mapToObject object: T? = nil, context: MapContext? = nil, completionHandler: @escaping (DataResponse<T>) -> Void) -> Self

The responseObject function has 4 optional parameters and a required completionHandler:

  • queue: The queue on which the completion handler is dispatched.
  • keyPath: The key path of the JSON where object mapping should be performed.
  • mapToObject: An object to perform the mapping on to.
  • context: A context object that is passed to the mapping function.
  • completionHandler: A closure to be executed once the request has finished and the data has been mapped by ObjectMapper.

Easy Mapping of Nested Objects

AlamofireObjectMapper supports dot notation within keys for easy mapping of nested objects. Given the following JSON String:

"distance" : {
     "text" : "102 ft",
     "value" : 31
}

You can access the nested objects as follows:

func mapping(map: Map) {
    distance <- map["distance.value"]
}

See complete documentation

KeyPath

The keyPath variable is used to drill down into a JSON response and only map the data found at that keyPath. It supports nested values such as data.weather to drill down several levels in a JSON response.

let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/2ee8f34d21e8febfdefb2b3a403f18a43818d70a/sample_keypath_json"
let expectation = expectationWithDescription("\(URL)")

Alamofire.request(URL).responseObject(keyPath: "data") { (response: DataResponse<WeatherResponse>) in
    expectation.fulfill()
    
    let weatherResponse = response.result.value
    print(weatherResponse?.location)
    
    if let threeDayForecast = weatherResponse?.threeDayForecast {
        for forecast in threeDayForecast {
            print(forecast.day)
            print(forecast.temperature)           
        }
    }
}

Array Responses

If you have an endpoint that returns data in Array form you can map it with the following function:

public func responseArray<T: Mappable>(queue queue: dispatch_queue_t? = nil, keyPath: String? = nil, completionHandler: DataResponse<[T]> -> Void) -> Self

For example, if your endpoint returns the following:

[
    { 
        "conditions": "Partly cloudy",
        "day" : "Monday",
        "temperature": 20 
    },
    { 
        "conditions": "Showers",
        "day" : "Tuesday",
        "temperature": 22 
    },
    { 
        "conditions": "Sunny",
        "day" : "Wednesday",
        "temperature": 28 
    }
]

You can request and map it as follows:

let URL = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/f583be1121dbc5e9b0381b3017718a70c31054f7/sample_array_json"
Alamofire.request(URL).responseArray { (response: DataResponse<[Forecast]>) in

    let forecastArray = response.result.value
    
    if let forecastArray = forecastArray {
        for forecast in forecastArray {
            print(forecast.day)
            print(forecast.temperature)           
        }
    }
}

Installation

AlamofireObjectMapper can be added to your project using CocoaPods by adding the following line to your Podfile:

pod 'AlamofireObjectMapper', '~> 5.2'

If you're using Carthage you can add a dependency on AlamofireObjectMapper by adding it to your Cartfile:

github "tristanhimmelman/AlamofireObjectMapper" ~> 5.2

alamofireobjectmapper's People

Contributors

alexmezabmw avatar alexseverinov avatar amolgupta avatar andre-wolfe avatar andres-cianio avatar bdbergeron avatar carlosmouracorreia avatar dennytwix avatar douglasheriot avatar enagorny avatar erikackermann avatar esetnik avatar fuxx avatar garie avatar goncharik avatar ikesyo avatar joesus avatar katsuyax avatar lluisgerard avatar louisdh avatar nevstad avatar patricks avatar paxswill avatar pizthewiz avatar readmecritic avatar robbiet480 avatar romanpodymov avatar schayes04 avatar tristanhimmelman avatar txaiwieser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alamofireobjectmapper's Issues

EXC_BAD_INSTRUCTION

I am getting data from my server. The response is:
{"languages":[{"language":"en","disabled":false}]}

When I do the request the code suddenly throws EXC_BAD_INSTRUCTION and it gets stuck in the error. If I remove inheritance Object from Language.swift it works ok

LanguageResponse.swift

import ObjectMapper

class LanguageResponse: Mappable {

    var languages: [Language]?

    required init?(_ map: Map){
    }

    override func mapping(map: Map) {
        super.mapping(map)
        languages <- map["languages"]
    }

}

Language.swift

import UIKit
import RealmSwift
import ObjectMapper

class Language: Object, Mappable {

    dynamic var language: String = ""

    override static func primaryKey() -> String? {
        return "language"
    }

    required convenience init?(_ map: Map) {
        self.init()
    }

    func mapping(map: Map) {
        language <- map["language"]
    }

}

Getting the Alamofire NSError

I'm unable to fetch the Alamofire response error when making a request.

The only error I am able to retrieve is the error
The operation couldnโ€™t be completed. ObjectMapper failed to serialize response.

i'm using version: 2.1

    Alamofire.request(.GET, url, parameters: nil, encoding: .JSON)
            .responseArray { (response: Response<[MyModel], NSError>) in

                if let error = response.result.error {
                    print("Error: \(error.localizedDescription)")
                    errorBlock(error)
                    return
                }

                completionBlock(response.result.value!)
        }

Support Swift-2.0

Error: Module file was created by an older version of the compiler.

Code signing failure when building 2.0.1

Something seems awry yet with the code signing setup in the project file, when building from source:

โ€ฆ
*** Checking out AlamofireObjectMapper at "2.0.1"
โ€ฆ
*** Building scheme "AlamofireObjectMapper iOS" in AlamofireObjectMapper.xcworkspace
** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)
CodeSign error: code signing is required for product type 'Framework' in SDK 'iOS 9.1'
A shell task failed with exit code 65:
** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)

Building 2.0.0 has no such issue.

Crash when mapping with valueOrFail

Hi first of all GREAT library here :) ....

I'm getting a weird crash when the requested key is not present in the response

public struct Response: Mappable {
    //MARK: Properties
    internal var dictionary: [String:AnyObject]
    //MARK: Mappable protocols implementation
    public init?(_ map: Map){
        self.dictionary = map["data"].valueOrFail()
        if !map.isValid {
            return nil
        }  
    }
    public mutating func mapping(map: Map) {
        dictionary    <- map["data"]
    } 
}

The response is:

{
            "login" :{ 
                "token":"451165846sdgfsgs6847653",
                "user_id":1
            }
}

It crash in Map.swift line 73

public func valueOrFail<T>() -> T {
        if let value: T = value() {
            return value
        } else {
            // Collects failed count
            failedCount++

            // Returns dummy memory as a proxy for type `T`
            let pointer = UnsafeMutablePointer<T>.alloc(0)
            pointer.dealloc(0)
            return pointer.memory
        }
    }

exactly on return pointer.memory

Thanks

Could I use My Own Error class?

Hi, normally Alamofire using for response
response: Response (MyMappableObject, NSError) in

And my service call return -> code 500 with json:
{"errorMessage":"Mail and password not matched"}

Could I use my own ErrorClass with object mapper? I mean change NSError with MyMappableErrorClass ?

my class just have one variable
var errorMessage: String?

Thx.

Framework not built when using Carthage

I expected to see a AlamofireObjectMapper.framework file but can only see the frameworks for Alamofire and ObjectMapper.framework.

Below is the contents of my Cartfile

github "Alamofire/Alamofire" >= 1.2
github "tristanhimmelman/AlamofireObjectMapper" ~> 0.4

License Issues

Hi Tristan, although your project License says MIT the header of your files are like this:

// Copyright (c) 2015 Tristan Himmelman. All rights reserved.

Do you think you can change that please?

Is it support ios 7

Is it support ios 7 ?
Why did the message '[!] The platform of the target XXXX (iOS 7.0) may not be compatible with AlamofireObjectMapper (0.2) which has a minimum requirement of iOS 8.0 - OS X 10.9.' occur ๏ผŸ

Ambiguous expression

I am getting the error "Type of expression is ambiguous without more context" in the following line:

Alamofire.request(.GET, URL).responseObject("data") { (response: Response <LanguageResponse, NSError>) in

i am using the last version of Alamofire

Unable to build OS X target w. Carthage

I am just starting to transition from pods to carthage, so it is highly possible I am doing something wrong ๐Ÿ˜„

Running carthage update fails with the following error while building the os x target:

The following build commands failed:
    CompileSwift normal x86_64 /Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapperTests/AlamofireObjectMapperTests.swift
    CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
ld: warning: directory not found for option '-F/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/Alamofire/build/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/Alamofire/build/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/Alamofire/build/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/Alamofire/build/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos'
ld: warning: directory not found for option '-F/Users/dev/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-dauotuqewdtvbqbcptlcgtwkqndr/Build/Products/Debug-iphoneos'
/Users/dev/Documents/Projects/swift/PGW-OSX/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapperTests/AlamofireObjectMapperTests.swift:11:8: error: no such module 'ObjectMapper'
A shell task failed with exit code 65

My Carthage file is bare-bones:

github "tristanhimmelman/AlamofireObjectMapper" ~> 0.7

I am getting the same no such module 'ObjectMapper' error in the IDE when I clone the AlamofireObjectMapper repo, run carthage update, open the workspace and then set the target to AlamofireObjectMapper OS X. Hitting build makes the error disappear, and I am able to run the tests afterwards.

I am running XCode 6.4 (6E35b)

Any ideas?

Pods giving compile time error

getting compile time error on this line mentioned below

<AppPath/AppName>/Pods/AlamofireObjectMapper/AlamofireObjectMapper/AlamofireObjectMapper.swift:49:10: Cannot invoke 'response' with an argument list of type '(queue: dispatch_queue_t?, serializer: GenericResponseSerializer, (_, _, _, _) -> Void)'

<AppPath/AppName>/Pods/AlamofireObjectMapper/AlamofireObjectMapper/AlamofireObjectMapper.swift:98:10: Cannot invoke 'response' with an argument list of type '(queue: dispatch_queue_t?, serializer: GenericResponseSerializer, (_, _, _, _) -> Void)'

Unable to build w/ Carthage

I think this project needs its own Cartfile with a dependency on Alamofire? New to Carthage so totally possible I am just doing something wrong ๐Ÿ˜…

/Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlmofireObjectMapper.swift:10:8:
error: no such module 'Alamofire'
import Alamofire
       ^
0  swift                    0x00000001048f5a18 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x00000001048f5ef4 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff8f4bff1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff5ba23868 _sigtramp + 3428202856
4  swift                    0x00000001041ddae6 main + 1814
5  libdyld.dylib            0x00007fff90df05c9 start + 1
6  libdyld.dylib            0x0000000000000047 start + 1864432255

Full output below...

=== BUILD TARGET AlamofireObjectMapper iOS OF PROJECT AlamofireObjectMapper WITH CONFIGURATION Release ===

Check dependencies

CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
    cd /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/chrismcc/.nvm/v0.11.14/bin:/usr/local/heroku/bin:/usr/local/bin:/usr/local/git/bin:./node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -target x86_64-apple-ios8.0 -incremental -module-name AlamofireObjectMapper -O -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.3.sdk -g -module-cache-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/ModuleCache -Xfrontend -serialize-debugging-options -I /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator -F /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator -F /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/Alamofire/build/Debug-iphoneos -F /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos -parse-as-library -c -j8 /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlmofireObjectMapper.swift -output-file-map /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/Objects-normal/x86_64/AlamofireObjectMapper\ iOS-OutputFileMap.json -parseable-output -serialize-diagnostics -emit-dependencies -emit-module -emit-module-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/Objects-normal/x86_64/AlamofireObjectMapper.swiftmodule -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/AlamofireObjectMapper-generated-files.hmap -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/AlamofireObjectMapper-own-target-headers.hmap -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/AlamofireObjectMapper-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/AlamofireObjectMapper-project-headers.hmap -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/DerivedSources/x86_64 -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/DerivedSources -emit-objc-header -emit-objc-header-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/Objects-normal/x86_64/AlamofireObjectMapper-Swift.h -import-underlying-module -Xcc -ivfsoverlay -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper\ iOS.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper

CompileSwift normal x86_64 /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlmofireObjectMapper.swift
    cd /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlmofireObjectMapper.swift -target x86_64-apple-ios8.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.3.sdk -I /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator -F /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator -F /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/Alamofire/build/Debug-iphoneos -F /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos -g -import-underlying-module -module-cache-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc "-I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/swift-overrides.hmap" -Xcc -iquote -Xcc "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/AlamofireObjectMapper-generated-files.hmap" -Xcc "-I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/AlamofireObjectMapper-own-target-headers.hmap" -Xcc "-I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/AlamofireObjectMapper-all-non-framework-target-headers.hmap" -Xcc -ivfsoverlay -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/all-product-headers.yaml -Xcc -iquote -Xcc "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/AlamofireObjectMapper-project-headers.hmap" -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc "-I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/DerivedSources/x86_64" -Xcc "-I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/DerivedSources" -Xcc -ivfsoverlay -Xcc "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/unextended-module-overlay.yaml" -Xcc -working-directory/Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper -emit-module-doc-path "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper~partial.swiftdoc" -O -parse-as-library -module-name AlamofireObjectMapper -emit-module-path "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper~partial.swiftmodule" -serialize-diagnostics-path "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper.dia" -emit-dependencies-path "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper.d" -emit-reference-dependencies-path "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper.swiftdeps" -o "/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper.o"
/Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlmofireObjectMapper.swift:10:8: error: no such module 'Alamofire'
import Alamofire
       ^
0  swift                    0x00000001048f5a18 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x00000001048f5ef4 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff8f4bff1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff5ba23868 _sigtramp + 3428202856
4  swift                    0x00000001041ddae6 main + 1814
5  libdyld.dylib            0x00007fff90df05c9 start + 1
6  libdyld.dylib            0x0000000000000047 start + 1864432255
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlmofireObjectMapper.swift -target x86_64-apple-ios8.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.3.sdk -I /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator -F /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator -F /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/Alamofire/build/Debug-iphoneos -F /Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper/Carthage/Checkouts/ObjectMapper/build/Debug-iphoneos -g -import-underlying-module -module-cache-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/AlamofireObjectMapper-generated-files.hmap -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/AlamofireObjectMapper-own-target-headers.hmap -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/AlamofireObjectMapper-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/AlamofireObjectMapper-project-headers.hmap -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Products/Release-iphonesimulator/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/DerivedSources/x86_64 -Xcc -I/Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/DerivedSources -Xcc -ivfsoverlay -Xcc /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/chrismcc/workspace/dummy/ios/Carthage/Checkouts/AlamofireObjectMapper -emit-module-doc-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper~partial.swiftdoc -O -parse-as-library -module-name AlamofireObjectMapper -emit-module-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper~partial.swiftmodule -serialize-diagnostics-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper.dia -emit-dependencies-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper.d -emit-reference-dependencies-path /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper.swiftdeps -o /Users/chrismcc/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-denivhzeqdyxuudexlorxdrsodrp/Build/Intermediates/AlamofireObjectMapper.build/Release-iphonesimulator/AlamofireObjectMapper iOS.build/Objects-normal/x86_64/AlmofireObjectMapper.o 

<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)

My cartfile looks like:

github "Alamofire/Alamofire" "1.2.1"
github "tristanhimmelman/AlamofireObjectMapper" "0.2"

ResponseObject, ResponseArray does not work for nested path

For Example if I have response starts with metadata.results I get serialization error:
Alamofire.request(.GET, BaseURL
,parameters: ["page": "0", "maxitems": "20"])
.responseObject("metadata.results") { (response: Response<T, NSError>) in
print (response)
};

Error: FAILURE: Error Domain=com.alamofire.error Code=-6004 "ObjectMapper failed to serialize response." UserInfo={NSLocalizedFailureReason=ObjectMapper failed to serialize response.}

array response with key

my server returns a response like this

{data:[array of devices]}

How can i get those kind of data? If I do responseArray i can't get it. If i do responseObject("data") I can't use an array. How should I do? Is this possible with object mapper?

Not work in Xcod 7.0 beta

Got the following error message:

The following build commands failed:
CompileSwift normal x86_64 /Users/Public/Test/Projects/TestProject/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlmofireObjectMapper.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)

Any idea? Thanks

Handle Nested JSON properties

lets say i get back json like this:

{
locations{
}
forecasts{
}
types
{
}
}

When I call responseObject or responseArray, I want to do that for one specific property. For example,
.responseArray { (response: <- [Location]?, "locations", error: NSError?) in

I don't care about forecasts or types in this instance. Perhaps this is an easy way to do this now I am missing.

Is there a way to pass a generic Type at runtime?

I'm using AlamofireObjectMapper to deserialize json responses from APIs, but I am struggling to write a generic function where I can pass an object at runtime.
If I have 3 objects A, B, C, right now I have to create 3 functions to deserialize in A, B, C.
I would like to only have 1 function that accept as a parameter the object type and pass it to the object mapper.

I've tried with Mirroring, and using the generic T, but I always get the error "is not a type".

some examples:

 func test<T>(cls: T.Type){

        let x = Mirror(reflecting: cls)
        Alamofire.request(.POST, endpoint).responseObject { (response:  Response<x, NSError>) in

            guard response.result.error == nil
                else {
                    return
            }
        }
    }

 func test<T>(cls: T.Type){

        Alamofire.request(.POST, endpoint).responseObject { (response:  Response<cls, NSError>) in

            guard response.result.error == nil
                else {
                    return
            }
        }
    }

Any hint? Thanks

Error: Cannot convert value of type 'T?' to expected argument type '_?'

I'm trying to implement AlamofireObjectMapper with Alamofire 3 and latest version of ObjectMapper (https://github.com/Hearst-DD/ObjectMapper).

It seems that AlamofireObjectMapper, hasn't been updated to work with Alamofire 3, so I'm trying to do it myself.

I've come to this piece of code and now i'm stuck.

It seems that the Generic Type T is not accesible inside the completion block of the response. Is a Alamofire 3 change or a Swift 2.1 change?

This is the error: Cannot convert value of type 'T?' to expected argument type '_?'

public func responseObject<T: Mappable>(queue: dispatch_queue_t?, keyPath: String?, completionHandler: (NSURLRequest, NSHTTPURLResponse?, T?, AnyObject?, ErrorType?) -> Void) -> Self {

return response(queue: queue) { (request, response, data, error) -> Void in
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
        let JSONResponseSerializer = Request.JSONResponseSerializer(options: .AllowFragments)
        let result = JSONResponseSerializer.serializeResponse(request, response, data, error)
        let parsedObject = Mapper<T>().map(keyPath != nil ? result.value?[keyPath!] : result.value)

        dispatch_async(queue ?? dispatch_get_main_queue()) {
            completionHandler(self.request!, self.response, parsedObject, result.value ?? response.data, result.error) // Here it shows the error: Cannot convert value of type 'T?' to expected argument type '_?' 
        }
    }
}

}

ObjectMapper failed to serialize response

Hi,

I'm trying to use AlamofireObjectMapper in a project with Switf 2 on Xcode 7.

I mapped an object into a class:
import Foundation
import ObjectMapper

class Item: Mappable {
var id: Int?
required init?(_ map: Map) {
}
func mapping(map: Map) {
id <- map["id"]
}
}

However, when I call it (as Github's example)
let URL = "xxx"
Alamofire.request(.GET, URL)
.responseObject("data") { (response: Response<Item, NSError>) in
print(response.result.value?.id)
print(response.result.error)
}

I got this error:
"Optional(Error Domain=com.alamofire.error Code=-6004 "ObjectMapper failed to serialize response." UserInfo={NSLocalizedFailureReason=ObjectMapper failed to serialize response.})"

This also happens with WeatherForecast example. What can be the problem?

version conflicts

[!] Unable to satisfy the following requirements: - Alamofire (~> 2.0) required by Podfile - Alamofire (~> 1.3) required by AlamofireObjectMapper (0.7)

Core Data

I want to save the models in core data database
is there any way to do this

Building for iphonesimulator

when installing via Carthage building for iphonesimulator fails if signature is not present (no iPhone developer account)
Base ObjectMapper library builds fine for iphonesimulator target

Doesn't support on iOS 7 because import Alamofire and ObjectMappe

The main problem is that iOS 7 doesn't support dynamic frameworks.

You can fix that with preprocessor flag ( Thanks to RxSwift :) ).

Add RX_NO_MODULE as a custom Swift preprocessor flag

if !AOM_NO_MODULE

import Alamofire
import ObjectMappe

endif

Thanks,
Guy

Carthage still embedding sub-frameworks

The shell script build phase that embedded the Alamofire and ObjectMapper frameworks into AlamofireObjectMapper was removed from the xcodeproj in #8, but it doesn't appear to be enough as building via Carthage still results in the embedded frameworks.

My Cartfile.resolved has the latest rev:

github "tristanhimmelman/AlamofireObjectMapper" "dc6fda6176e944c73caf0fe76b6bf1db5a37013f"

and I can confirm that if I run

$ cd Carthage/Checkouts/AlamofireObjectMapper/; xcodebuild

the build product does not have the embedded frameworks, so I wonder I Carthage is building the project via some other mechanism.

responseArray Cocoa 3840 error

I'm completely new to Swift/iOS development in general so pardon me if I've missed something obvious.
I have an API endpoint returning valid JSON Array:

[
    {
        "id":23,
        "amount":4000.0,
        "date":"2015-08-05",
        "description":null,
        "include_gst":true,
        "user_id":15,
        "gst_amount":363.6363636363636,
        "customer_id":null,
        "customer":null
    },
    {
        "id":19,
        "amount":150.0,
        "date":"2015-07-18",
        "description":"Proba",
        "include_gst":true,
        "user_id":15,
        "gst_amount":13.63636363636364,
        "customer_id":null,
        "customer":null
    }
]

However, when using responseArray method, it fails with the following error:

error   NSError?    domain: "NSCocoaErrorDomain" - code: 3840   0x00007fc0abcd0230

Here is the code that produces it:

class RoundedClient {

    private var username: String?
    private var password: String?

    private let rootUrl = "http://localhost:3000/"

    func getIncomeRecords() -> Future<[IncomeRecord], RequestError> {
        let promise = Promise<[IncomeRecord], RequestError>()

        Alamofire.request(.GET, getUrl("income_records"))
            .authenticate(user: username!, password: password!)
            .responseArray { (response: [IncomeRecord]?, error: NSError?) in
                if response != nil {
                    promise.success(response!)
                } else {
                    promise.failure(RequestError(message: "Request failure"))
                }
            }

        return promise.future
    }

    private func getUrl(path: String) -> String {
        return rootUrl + path
    }

    class IncomeRecord: Mappable {
        var amount: Float?
        var description: String?
        var includeGst: Bool?

        static func newInstance() -> Mappable {
            return IncomeRecord()
        }

        func mapping(map: Map) {
            amount <- map["amount"]
            description <- map["description"]
            includeGst <- map["include_gst"]
        }
    }
}

Responses which return objects work fine with responseObject method. Could anybody shed some light on this?

Handle Array Response

How does one handle a response that is an array? i.e. -

[{"id":1,"name":"Erik"},{"id":1,"name":"Kimberly"}]

Recommended way to test mappings

In my project I have written some model classes that fetch data via Alamofire, Objectmapper and Realm. Sometimes a backend developer changes the REST-interface or a dog walks across my keyboard, so that my mapping breaks.

I would like to increase my test coverage and detect if my mapping doesn't fit to the REST-service anymore. What would be the best approach to test this?

Here is a method thats would be great to have tested:

 func fetchOverviewItemList(successHandler: List<OverviewItem> -> (), errorHandler: (ErrorType?) -> ()){

        //fetch existing objects from DB
        let overviewItemsAsList = List<OverviewItem>()
        overviewItemsAsList.appendContentsOf(self.realm.objects(OverviewItem))
        successHandler(overviewItemsAsList)

        AlamofireManager.Configured
            .request(.GET, URLs.sharedInstance.overviewItemsUrl())
            .responseJSON{response in log.verbose("response: \(response.result.value)")}
            .responseArray("sefInfos") { (response: Response<[OverviewItem], NSError>) in

                if let error = response.result.error{
                    log.error("Error: \(error.localizedDescription)")
                    errorHandler(error)
                    return
                }

                if let overviewItemsArray = response.result.value{

                    //remove orphans
                    self.deleteOrphans(overviewItemsAsList, fetchedData: overviewItemsArray)


                    //update objects from service
                    overviewItemsAsList.removeAll()
                    overviewItemsAsList.appendContentsOf(overviewItemsArray)
                    successHandler(overviewItemsAsList)

                    do{
                        try self.realm.write{
                            self.realm.add(overviewItemsAsList, update: true)
                        }
                    }
                    catch let err as NSError {
                        log.error("Error with realm: \(err.localizedDescription)")
                    }
                }
        }
    }

Pod can`t install

Hi.
The cocoapods returns:

[!] Unable to satisfy the following requirements:

- `Alamofire (~> 2.0.2)` required by `Podfile`                                                                                
- `Alamofire (= 2.0.2)` required by `Podfile.lock`                                                                            
- `Alamofire (= 2.0.0)` required by `AlamofireObjectMapper (0.9)`

My Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target 'Doge' do
    pod 'PureLayout'
    pod 'RealmSwift'
    pod 'Alamofire', '~> 2.0.2'
    pod 'ObjectMapper', '~> 0.17'
    pod 'Nuke'
    pod 'kingpin'
end

Anyone knows what can be?

** BUILD FAILED **

*** Fetching AlamofireObjectMapper
*** Fetching Alamofire
*** Fetching ObjectMapper
*** Checking out ObjectMapper at "1.0.1"
*** Checking out Alamofire at "3.1.4"
*** Checking out AlamofireObjectMapper at "2.1.0"
*** xcodebuild output can be found in /var/folders/gp/5xhpyxj54pvb185s6t67sp980000gp/T/carthage-xcodebuild.TEJVi6.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire OSX" in Alamofire.xcworkspace
*** Building scheme "Alamofire tvOS" in Alamofire.xcworkspace
*** Building scheme "Alamofire watchOS" in Alamofire.xcworkspace
*** Building scheme "ObjectMapper-Mac" in ObjectMapper.xcworkspace
*** Building scheme "ObjectMapper-watchOS" in ObjectMapper.xcworkspace
*** Building scheme "ObjectMapper-tvOS" in ObjectMapper.xcworkspace
*** Building scheme "ObjectMapper-iOS" in ObjectMapper.xcworkspace
*** Building scheme "AlamofireObjectMapper iOS" in AlamofireObjectMapper.xcworkspace
*** Building scheme "AlamofireObjectMapper watchOS" in AlamofireObjectMapper.xcworkspace
** BUILD FAILED **


The following build commands failed:
    CompileSwift normal armv7k /Users/paulomcnally/github/SelfieDescuentos/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlamofireObjectMapper.swift
    CompileSwiftSources normal armv7k com.apple.xcode.tools.swift.compiler
(2 failures)
/Users/paulomcnally/github/SelfieDescuentos/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlamofireObjectMapper.swift:31:8: error: module file's minimum deployment target is watchos2.1 v2.1: /Users/paulomcnally/Library/Developer/Xcode/DerivedData/AlamofireObjectMapper-ekvtjzjwgicbrdffunyfsynwdcib/Build/Products/Release-watchos/ObjectMapper.framework/Modules/ObjectMapper.swiftmodule/arm.swiftmodule
A shell task failed with exit code 65:
** BUILD FAILED **


The following build commands failed:
    CompileSwift normal armv7k /Users/paulomcnally/github/SelfieDescuentos/Carthage/Checkouts/AlamofireObjectMapper/AlamofireObjectMapper/AlamofireObjectMapper.swift
    CompileSwiftSources normal armv7k com.apple.xcode.tools.swift.compiler
(2 failures)

Not working with mutableURLRequest

let URL = NSURL(string: String(format:"/y/%@",communityId))!
let mutableURLRequest = NSMutableURLRequest(URL: URL)
mutableURLRequest.HTTPMethod = "GET"
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
mutableURLRequest.setValue(DataEnv.sharedManager.username, forHTTPHeaderField: "X-Auth-Token")

Alamofire.request(mutableURLRequest)
.responseObject { (response: CommunityModel?, error: NSError?) in
if let response = response {
self.communityInfo = response
MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
self.tableView.reloadData()
}
}

error with:
can not invoke responseObject with argument list type of ...

support to swift List Realm class

Hi all,

We are developing with swift 2.0 and we're using alamofire 3.0, Realm 0.96, and your last version of ObjectMapper
We have some entities that inherits from Object (to persist in Realm) and implements Mappable protocol. We have the following classes

class A: Object, Mappable{

dynamic var name : String?
let productGroup = List()

required convenience init?(_ map: Map) {
self.init()
}

func mapping(map: Map) {
name <- map["name"]
productGroup <- map["productGroup"]

}

class ProductGroup: Mappable {
dynamic var name : String?
dynamic var urlPhoto : String?
dynamic var currency : String?

required convenience init?(_ map: Map) {
    self.init()
}

  func mapping(map: Map) {
       name <- map["name"]
       currency <- map["currency"]
       urlPhoto <- map["urlPhoto"]
  }

}
object A has a list of productGroup (supported by Realm to keep them persistently). When we parse them within the A class mapping, productGroup is not populated because is not entering to the ProductGroup mapping function.

Are you going to support nested objects using List?

Best regards,

Alfonso.

Update doc

Hi,

In 'Array Responses' chapter, the code line 'println(response?.location)' has nothing to do in this example.
And for all the examples, println are now replaced by print in swift2.

Thanks!

I always got 'objectmapper failed to serialize response' when parsing error response

import Foundation
import ObjectMapper
import AlamofireObjectMapper

private let NameKey = "name"
private let DescriptionKey = "description"
private let CoverURLKey = "cover_url"
private let MembersAmountKey = "members_count"
private let SportNameKey = "sport_name"
private let PagePolicyKey = "policy"

class Tribe: Mappable {
    var name: String?
    var desc: String?
    var coverURL: NSURL?
    var membersAmount: Int?
    var sportName: String?
    var policy: ObjectPolicy?
    required init?(_ map: Map){

    }

    func mapping(map: Map) {
        name <- map[NameKey]
        desc <- map[DescriptionKey]
        coverURL <- (map[CoverURLKey], URLTransform())
        membersAmount <- map[MembersAmountKey]
        sportName <- map[SportNameKey]
        policy <- map[PagePolicyKey]
    }
}

this is my class and I just used simply -responseObject object method in APIClient
Thank in advance.

Realm-support

Is there a trick to save the mapped Realm-Objects to Realm?

AlamofireManager.Configured
            .request(.GET, URLs.sharedInstance.getContactsUrl())
            .responseArray("contactHeaders") { (response: Response<[ParticipantData], NSError>) in

                if let error = response.result.error{
                    print("Error: \(error.localizedDescription)")
                    errorHandler(error)
                    return
                }

                if let participantsArray = response.result.value{
                    successHandler(participantsArray)

                    do{
                        try self.realm.write{
                            self.realm.add(participantsArray, update: true)
                        }
                    }
                    catch let err as NSError {
                        print("Error with realm: " + err.localizedDescription)
                    }
                }
        }

In my example I fetch an Array of ParticipantData (Type, Object, Mappable) from the server. I can iterate over the array and print all the mapped properties. Then I store them to realm. But realm saves empty objects - each property is empty. Any idea?

responseArray build error

I'm using request for "responseArray" but build failed with this error:

Cannot invoke 'responseArray' with an argument list of type '((Response<[CouponResponse], NSError>) -> Void)'

Code:
Alamofire.request(.GET, URL).responseArray { (response: Response<[CouponResponse], NSError>) -> Void in
if let couponRes = response.result.value {
print(couponRes[0].result)
}
}

How to solve this problem? Thx

Swift 2.0 problems

I get a lot of problem when using your Swift 2.0 branch with Alamo Swift 2.0 and ObjectMapper Swift 2.0 branches...

How to Print the Response

After executing the following statement, how I be sure data has been imported correctly.

 let user = Mapper<User>().map(JSONString)

Basically I want to print the user object on console to see what has been mapped.

Thanks.

tvOS + Pods

When i try to add/install the objectmanager via cocoapods by adding:

pod 'AlamofireObjectMapper', '~> 2.0'

and run 'pods install'

With 'platform :tvos, '9.0'

It tells me that The platform of the target 'Pods' is not compatible with 'AlamoforeObjectManager (2.0.0)', which does not support 'tvos'.

Is cocoapods not supported yet on the new version, that been added 2 days ago, telling that tvos is now supported??

/Anders

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.