<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">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 <font face="Courier" class="">NSXMLNode</font> is <font face="Courier" class="">init(kind: NSXMLNodeKind, options: Int)</font>. In pure Swift, this <i class="">always</i> returns an NSXMLNode, not the appropriate subclass! Which, of course, means <font face="Courier" class="">as?</font> returns nil, <font face="Courier" class="">as!</font> (and <font face="Courier" class="">unsafeDowncast</font>) 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?<div class=""><br class=""></div><div class="">Thanks,</div><div class="">Robert Thompson</div><div class="">Software Engineer<br class="">WillowTree, Inc.®<br class=""><a href="http://willowtreeapps.com" class="">willowtreeapps.com</a><br class=""> <img apple-inline="yes" id="0C587504-4898-4B3F-A72A-5F62109770FC" height="40" width="183" apple-width="yes" apple-height="yes" src="cid:04F0A8D2-F0EB-4FC5-9305-30B7966DFEA6@willowtree.lan" class=""></div></body></html>