avdlee / moya-swiftyjsonmapper Goto Github PK
View Code? Open in Web Editor NEWMap objects through SwiftyJSON in combination with Moya
License: MIT License
Map objects through SwiftyJSON in combination with Moya
License: MIT License
Hi
I encountered this problem
In the app json which comes from the server looks like
{ result: [{...}, {...}] }
To parse it need create an object with variable "result" which contains an array of other objects
how can i parse array from variable "result" without create object which contains it?
I receive JSON with nested array like:
{
"size": 20,
"items": [
{
"id": "28266",
"type": "Feed\\ItemCommented",
"view_name": "notification_commented",
"text": "Lorem ipsum",
"read": false,
"created_at": "2017-02-15T09:54:20+00:00",
},
{...}
]
}
I would like to map field "items" to array of Notification objects:
var notifications = [Notification]()
I try with such code:
self.notifications = try response.map(to: [Notification.self])
but it doesn't work because of nested items field.
Response+SwiftyJSONMapper.swift line:32
'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value
CocoaPods version 1.0.0
[!] Unable to satisfy the following requirements:
- `RxSwift` required by `Podfile`
- `RxSwift (~> 2.4)` required by `RxPermission (0.1.1)`
- `RxSwift (~> 2.0.0)` required by `Moya-SwiftyJSONMapper/RxSwift (1.0.3)`
- `RxSwift (~> 2.0)` required by `RxNimble (0.2.0)`
Will be a Carthage support?
Dependency "Moya-SwiftyJSONMapper" has no shared framework schemes for any of the platforms: iOS
Please update your podspec file so that SwiftyJSON can be version 2.4.x or higher.
Hi, I need this new version of Moya-swiftyJSONMapper to fit with last Alamofire (linked dependancy)
But I can't manage to have this latest version to install. At best I have the 5.0 that install.
here is my pod file on a sample project
target 'TestMoya' do
use_frameworks!
pod "Moya-SwiftyJSONMapper", '~> 6.0'
target 'TestMoyaTests' do
inherit! :search_paths
end
target 'TestMoyaUITests' do
end
end
here is the response:
TestMoya % pod install
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "Moya-SwiftyJSONMapper":
In Podfile:
Moya-SwiftyJSONMapper (~> 6.0)
None of your spec sources contain a spec satisfying the dependency: `Moya-SwiftyJSONMapper (~> 6.0)`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
So I tried to force the repo location with "source" since there is a pod spec in this git. but still no luck.
Thanks for your help
Now that there is a new version of Moya, please update the pod spec (and classes) to use the Moya v10
I installed this pod with 'Moya-SwiftyJSONMapper/RxSwift' and it automaticly downgrade following pods
I have an issue when mapping over an array using the function
public func map<T: ALSwiftyJSONAble>(to type:[T.Type]) throws -> [T] {
let jsonObject = try mapJSON()
let mappedArray = JSON(jsonObject)
let mappedObjectsArray = mappedArray.arrayValue.flatMap { T(jsonData: $0) }
return mappedObjectsArray
}
The bit that maps each item of the array is not allowed to fail because of the use of flatMap
. For example, if the array contains three items of data of which two are valid, no errors will be thrown and an array of size two will be returned.
In some cases, it would be more useful if an error were thrown if the array contains invalid JSON (ie. returned nil from the init()
function).
Similar to the function
public func map<T: ALSwiftyJSONAble>(to type:T.Type) throws -> T {
let jsonObject = try mapJSON()
guard let mappedObject = T(jsonData: JSON(jsonObject)) else {
throw MoyaError.jsonMapping(self)
}
return mappedObject
}
where the guard clause throws a MoyaError
if the mapping is nil.
I can perform the map myself but I would rather contain the abstraction at its current level.
Hi
how to do something similar to this:
name = jsonData["User_Info"]["UName"].stringValue
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.