Code Monkey home page Code Monkey logo

Comments (5)

tadija avatar tadija commented on August 16, 2024

It's just a regular [NSObject : AnyObject] dictionary.

You can do it like this:

var theColor = "yellow"
xmlDoc.root["cats"]["cat"].allWithAttributes(["breed" : "Domestic", "color" : theColor])

from aexml.

 avatar commented on August 16, 2024

Unfortunately it doesn't work as suggested;
Type 'String' does not conform to protocol 'AnyObject'

from aexml.

tadija avatar tadija commented on August 16, 2024

I don't have time to go deep into this now, but can you try this workaround:

var theKey = "color" as NSObject
var theValue = "yellow" as NSObject
let theAttributes = [theKey : theValue]
if let cats = xmlDoc.root["cats"]["cat"].allWithAttributes(theAttributes) {
    // do something
}

Casting key and value to NSObject should get rid of that compiler error, I know it's not perfect but it's a start.

from aexml.

angerthosenear avatar angerthosenear commented on August 16, 2024

Taking this a step further, I'm trying to overwrite an element if my new node matches an attribute.

let date = "date" as NSObject
let dateFor = (xmlDoc.root.attributes["date"] as! String) as NSObject
let theAttributes = [date: dateFor]

let newEntry = xmlToWrite.root

if var entry = xmlDoc.allWithAttributes(theAttributes){
    entries = [entryToWrite] //there will only ever be 1
}
//else it will just add a child element

xmlDoc.root has multiple attributes (the other being an entered date), so I cannot just snag all of them to plug into the allWithAttributes.

I feel like it's close and I'm just missing something here.

Thanks for your help.

from aexml.

pyanfield avatar pyanfield commented on August 16, 2024

I have the same problems,casting the value to NSObject works for me.

from aexml.

Related Issues (20)

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.