Skip to content
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

Issue with optional attributes in simple tags #29

Closed
gcharita opened this issue Apr 13, 2020 · 0 comments · Fixed by #30
Closed

Issue with optional attributes in simple tags #29

gcharita opened this issue Apr 13, 2020 · 0 comments · Fixed by #30
Assignees
Labels

Comments

@gcharita
Copy link
Owner

There is an issue on mapping simple tags (a tag with just inner text) that have optional attributes.

When there is at least one attribute present, everything work fine:

<root>
    <tag optionalAttribute="attribute value">innetText</testString>
</root>

But when there is no attribute present:

<root>
    <tag>innetText</testString>
</root>

mapping using the same model produces nil:

class Root: XMLMappable {
    var nodeName: String!
    
    var tag: Tag?
    
    required init?(map: XMLMap) {}
    
    func mapping(map: XMLMap) {
        tag <- map["tag"]
    }
}

class Tag: XMLMappable {
    var nodeName: String!
    
    var optionalAttribute: String?
    var text: String?
    
    required init?(map: XMLMap) {}
    
    func mapping(map: XMLMap) {
        optionalAttribute <- map.attributes["optionalAttribute"]
        text <- map.innerText
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant