New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
foobar2000 returns artist twice - once with just text, second time with attribute - XMLMapper can't access second array item #34
Comments
@mgainesdev thank you for using this library. I tested you example and this doesn't happen on my side. Could you please share your XMLMapper version? |
Sure. I didn't want to post TOO much data.
The version I'm using is 1.6.1 EDIT: Here are two of the related classes I'm using
|
@mgainesdev again, sorry for the late response. Your model is correct and has as a result the correct mapping of the provided XML: class SOAPItemAlbumArtist: XMLMappable {
required init?(map: XMLMap) {}
var nodeName: String!
var artistName: String?
var artistRole: String?
func mapping(map: XMLMap) {
artistName <- map.innerText
artistRole <- map.attributes["role"]
}
}
class SOAPRes: XMLMappable {
required init?(map: XMLMap) {}
var nodeName: String!
var duration: String?
var size: String?
var bitrate: String?
var bitsPerSample: String?
var sampleFrequency: String?
var nrAudioChannels: String?
var protocolInfo: String?
var url: URL?
func mapping(map: XMLMap) {
duration <- map.attributes["duration"]
size <- map.attributes["size"]
bitrate <- map.attributes["bitrate"]
bitsPerSample <- map.attributes["bitsPerSample"]
sampleFrequency <- map.attributes["sampleFrequency"]
nrAudioChannels <- map.attributes["nrAudioChannels"]
protocolInfo <- map.attributes["protocolInfo"]
url <- (map.innerText, XMLURLTransform())
}
}
class SOAPItem: XMLMappable {
private static let dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
return dateFormatter
}()
required init?(map: XMLMap) {}
var nodeName: String!
var id: String?
var parentID: String?
var restricted: String?
var title: String?
var creator: String?
var date: Date?
var artist: [SOAPItemAlbumArtist]?
var album: String?
var albumArtURI: URL?
var longDescription: String?
var originalTrackNumber: Int?
var res: [SOAPRes]?
var `class`: String?
func mapping(map: XMLMap) {
id <- map.attributes["id"]
parentID <- map.attributes["parentID"]
restricted <- map.attributes["restricted"]
title <- map["dc:title"]
creator <- map["dc:creator"]
date <- (map["dc:date"], XMLDateFormatterTransform(dateFormatter: SOAPItem.dateFormatter))
artist <- map["upnp:artist"]
album <- map["upnp:album"]
albumArtURI <- (map["upnp:albumArtURI"], XMLURLTransform())
longDescription <- map["upnp:longDescription"]
originalTrackNumber <- map["upnp:originalTrackNumber"]
res <- map["res"]
`class` <- map["upnp:class"]
}
} Apart from some minor changes that I made for the model to be prettier, everything else left intact. And here are the result from the debugger: One last question: Are you using cocoapods, Carthage or SPM? |
@mgainesdev is there any news on this? Did you tried the proposed model for your mapping? |
Closing this issue as stale. Feel free to reopen it if the problem persists. |
Good day,
I found a problem when trying to connect to a foobar2000 server.
The server returns:
And that's ok, because XMLMapper treats it like an array.
However, I can't access the second item, no matter what I try.
If I map it to a String, I just get the first item. Ok, that's fine, but the second item gets lost.
So then I tried creating a new class:
And then the definition is as such:
var artist: [SOAPItemAlbumArtist]?
That causes a crash in XMLMapper.swift:90
if var object = klass.init(map: map) as? N {
I tried everything I could to figure this out, including tracing through the source code but I'm not familiar enough with it to determine exactly how to fix it, or if I'm just setting up my mapping incorrectly.
Has anyone seen this issue? Is it a bug, or user error?
The text was updated successfully, but these errors were encountered: