[swift-corelibs-dev] NSXMLNode and Friends

Robert Stephen Thompson robert.thompson at willowtreeapps.com
Fri Dec 18 11:21:04 CST 2015


Since I recently did a small implementation of NSXMLNode and NSXMLDocument to use in an iOS project, I decided to tackle doing the full-featured one here. It’s not that hard, doing it as a wrapper on libxml2, except I’ve run into a bit of a snag with making the semantics exactly match Darwin Foundation: you can’t return a subclass from init! This really only matters in one place, but it matters quite a bit there. The de facto designated initializer for NSXMLNode is init(kind: NSXMLNodeKind, options: Int). In pure Swift, this always returns an NSXMLNode, not the appropriate subclass! Which, of course, means as? returns nil, as! (and unsafeDowncast) crash, etc, when you end up trying to retrieve one and treat it as the subclass it’s “supposed” to be. I’m completely stumped as to any way around this. It might be that it’s just impossible to match Darwin Foundation semantics without a new language feature for this, which obviously would have to go through swift-evolution and then actually be implemented. Am I correct, or is there something I’m missing? Also, should I go ahead and implement the rest of this without the exactly matching semantics because something is better than nothing?

Thanks,
Robert Thompson
Software Engineer
WillowTree, Inc.®
willowtreeapps.com
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20151218/23c6289b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-1.png
Type: image/png
Size: 8609 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20151218/23c6289b/attachment.png>


More information about the swift-corelibs-dev mailing list