[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7096":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":16,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":17,"rankGlobal":10,"rankLanguage":10,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":16,"starSnapshotCount":16,"syncStatus":26,"lastSyncTime":27,"discoverSource":28},7096,"AlamofireObjectMapper","tristanhimmelman\u002FAlamofireObjectMapper","tristanhimmelman","An Alamofire extension which converts JSON response data into swift objects using ObjectMapper","",null,"Swift",2650,476,47,52,0,60.04,"MIT License",false,"master",true,[],"2026-06-12 04:00:32","AlamofireObjectMapper\n============\n[![Build Status](https:\u002F\u002Ftravis-ci.org\u002Ftristanhimmelman\u002FAlamofireObjectMapper.svg?branch=master)](https:\u002F\u002Ftravis-ci.org\u002Ftristanhimmelman\u002FAlamofireObjectMapper)\n[![CocoaPods](https:\u002F\u002Fimg.shields.io\u002Fcocoapods\u002Fv\u002FAlamofireObjectMapper.svg)](https:\u002F\u002Fgithub.com\u002Ftristanhimmelman\u002FAlamofireObjectMapper)\n[![Carthage compatible](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FCarthage-compatible-4BC51D.svg?style=flat)](https:\u002F\u002Fgithub.com\u002FCarthage\u002FCarthage)\n\n\nAn extension to [Alamofire](https:\u002F\u002Fgithub.com\u002FAlamofire\u002FAlamofire) which automatically converts JSON response data into swift objects using [ObjectMapper](https:\u002F\u002Fgithub.com\u002FHearst-DD\u002FObjectMapper\u002F). \n\n# Usage\n\nGiven a URL which returns weather data in the following form:\n```\n{\n    \"location\": \"Toronto, Canada\",    \n    \"three_day_forecast\": [\n        { \n            \"conditions\": \"Partly cloudy\",\n            \"day\" : \"Monday\",\n            \"temperature\": 20 \n        },\n        { \n            \"conditions\": \"Showers\",\n            \"day\" : \"Tuesday\",\n            \"temperature\": 22 \n        },\n        { \n            \"conditions\": \"Sunny\",\n            \"day\" : \"Wednesday\",\n            \"temperature\": 28 \n        }\n    ]\n}\n```\n\nYou can use the extension as the follows:\n```swift\nimport AlamofireObjectMapper\n\nlet URL = \"https:\u002F\u002Fraw.githubusercontent.com\u002Ftristanhimmelman\u002FAlamofireObjectMapper\u002Fd8bb95982be8a11a2308e779bb9a9707ebe42ede\u002Fsample_json\"\nAlamofire.request(URL).responseObject { (response: DataResponse\u003CWeatherResponse>) in\n\n    let weatherResponse = response.result.value\n    print(weatherResponse?.location)\n    \n    if let threeDayForecast = weatherResponse?.threeDayForecast {\n        for forecast in threeDayForecast {\n            print(forecast.day)\n            print(forecast.temperature)           \n        }\n    }\n}\n```\n\nThe `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:\u002F\u002Fgithub.com\u002FHearst-DD\u002FObjectMapper\u002F) `Mappable` protocol. In the above example, the `WeatherResponse` object looks like the following:\n\n```swift\nimport ObjectMapper\n\nclass WeatherResponse: Mappable {\n    var location: String?\n    var threeDayForecast: [Forecast]?\n    \n\trequired init?(map: Map){\n\n\t}\n    \n    func mapping(map: Map) {\n        location \u003C- map[\"location\"]\n        threeDayForecast \u003C- map[\"three_day_forecast\"]\n    }\n}\n\nclass Forecast: Mappable {\n    var day: String?\n    var temperature: Int?\n    var conditions: String?\n    \n\trequired init?(map: Map){\n\n\t}\n    \n    func mapping(map: Map) {\n        day \u003C- map[\"day\"]\n        temperature \u003C- map[\"temperature\"]\n        conditions \u003C- map[\"conditions\"]\n    }\n}\n```\n\nThe 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: \n```swift\npublic func responseObject\u003CT: BaseMappable>(queue: DispatchQueue? = nil, keyPath: String? = nil, mapToObject object: T? = nil, context: MapContext? = nil, completionHandler: @escaping (DataResponse\u003CT>) -> Void) -> Self\n```\nThe `responseObject` function has 4 optional parameters and a required completionHandler:\n- `queue`: The queue on which the completion handler is dispatched.\n- `keyPath`: The key path of the JSON where object mapping should be performed.\n- `mapToObject`: An object to perform the mapping on to.\n- `context`: A [context object](https:\u002F\u002Fgithub.com\u002FHearst-DD\u002FObjectMapper\u002F#mapping-context) that is passed to the mapping function.\n- `completionHandler`: A closure to be executed once the request has finished and the data has been mapped by ObjectMapper.\n\n### Easy Mapping of Nested Objects\n\nAlamofireObjectMapper supports dot notation within keys for easy mapping of nested objects. Given the following JSON String:\n```json\n\"distance\" : {\n     \"text\" : \"102 ft\",\n     \"value\" : 31\n}\n```\nYou can access the nested objects as follows:\n```swift\nfunc mapping(map: Map) {\n    distance \u003C- map[\"distance.value\"]\n}\n```\n[See complete documentation](https:\u002F\u002Fgithub.com\u002FHearst-DD\u002FObjectMapper#easy-mapping-of-nested-objects)\n\n### KeyPath\n\nThe `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.\n```swift\nlet URL = \"https:\u002F\u002Fraw.githubusercontent.com\u002Ftristanhimmelman\u002FAlamofireObjectMapper\u002F2ee8f34d21e8febfdefb2b3a403f18a43818d70a\u002Fsample_keypath_json\"\nlet expectation = expectationWithDescription(\"\\(URL)\")\n\nAlamofire.request(URL).responseObject(keyPath: \"data\") { (response: DataResponse\u003CWeatherResponse>) in\n    expectation.fulfill()\n    \n    let weatherResponse = response.result.value\n    print(weatherResponse?.location)\n    \n    if let threeDayForecast = weatherResponse?.threeDayForecast {\n        for forecast in threeDayForecast {\n            print(forecast.day)\n            print(forecast.temperature)           \n        }\n    }\n}\n```\n\n# Array Responses\nIf you have an endpoint that returns data in `Array` form you can map it with the following function:\n```swift\npublic func responseArray\u003CT: Mappable>(queue queue: dispatch_queue_t? = nil, keyPath: String? = nil, completionHandler: DataResponse\u003C[T]> -> Void) -> Self\n```\n\nFor example, if your endpoint returns the following:\n```\n[\n    { \n        \"conditions\": \"Partly cloudy\",\n        \"day\" : \"Monday\",\n        \"temperature\": 20 \n    },\n    { \n        \"conditions\": \"Showers\",\n        \"day\" : \"Tuesday\",\n        \"temperature\": 22 \n    },\n    { \n        \"conditions\": \"Sunny\",\n        \"day\" : \"Wednesday\",\n        \"temperature\": 28 \n    }\n]\n```\nYou can request and map it as follows:\n```swift\nlet URL = \"https:\u002F\u002Fraw.githubusercontent.com\u002Ftristanhimmelman\u002FAlamofireObjectMapper\u002Ff583be1121dbc5e9b0381b3017718a70c31054f7\u002Fsample_array_json\"\nAlamofire.request(URL).responseArray { (response: DataResponse\u003C[Forecast]>) in\n\n    let forecastArray = response.result.value\n    \n    if let forecastArray = forecastArray {\n        for forecast in forecastArray {\n            print(forecast.day)\n            print(forecast.temperature)           \n        }\n    }\n}\n\n```\n\n# Installation\nAlamofireObjectMapper can be added to your project using [CocoaPods](https:\u002F\u002Fcocoapods.org\u002F) by adding the following line to your Podfile:\n```\npod 'AlamofireObjectMapper', '~> 5.2'\n```\n\nIf you're using [Carthage](https:\u002F\u002Fgithub.com\u002FCarthage\u002FCarthage) you can add a dependency on AlamofireObjectMapper by adding it to your Cartfile:\n```\ngithub \"tristanhimmelman\u002FAlamofireObjectMapper\" ~> 5.2\n```\n","AlamofireObjectMapper 是一个 Alamofire 扩展，它能够自动将 JSON 响应数据转换为 Swift 对象。该项目利用了 ObjectMapper 库来实现这一功能，使得开发者可以更方便地处理网络请求返回的数据。其核心在于通过定义遵循 Mappable 协议的自定义对象，并在发起请求时指定这些对象类型，从而直接获取到结构化的数据结果。此工具非常适合需要频繁与 RESTful API 交互且响应体为 JSON 格式的 iOS 或 macOS 应用开发场景中使用，能够显著简化编码工作量并提高代码可读性。",2,"2026-06-11 03:10:29","top_language"]