#[repr(C)]pub struct NSXMLDocument { /* private fields */ }
NSXMLDocument
and NSXMLNode
only.Expand description
An XML Document
Note: if the application of a method would result in more than one element in the children array, an exception is thrown. Trying to add a document, namespace, attribute, or node with a parent also throws an exception. To add a node with a parent first detach or create a copy of it.
See also Apple’s documentation
Implementations§
Source§impl NSXMLDocument
impl NSXMLDocument
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn initWithXMLString_options_error(
this: Allocated<Self>,
string: &NSString,
mask: NSXMLNodeOptions,
) -> Result<Retained<Self>, Retained<NSError>>
Available on crate features NSError
and NSString
and NSXMLNodeOptions
only.
pub unsafe fn initWithXMLString_options_error( this: Allocated<Self>, string: &NSString, mask: NSXMLNodeOptions, ) -> Result<Retained<Self>, Retained<NSError>>
NSError
and NSString
and NSXMLNodeOptions
only.Returns a document created from either XML or HTML, if the HTMLTidy option is set. Parse errors are returned in error .
Sourcepub unsafe fn initWithContentsOfURL_options_error(
this: Allocated<Self>,
url: &NSURL,
mask: NSXMLNodeOptions,
) -> Result<Retained<Self>, Retained<NSError>>
Available on crate features NSError
and NSURL
and NSXMLNodeOptions
only.
pub unsafe fn initWithContentsOfURL_options_error( this: Allocated<Self>, url: &NSURL, mask: NSXMLNodeOptions, ) -> Result<Retained<Self>, Retained<NSError>>
NSError
and NSURL
and NSXMLNodeOptions
only.Returns a document created from the contents of an XML or HTML URL. Connection problems such as 404, parse errors are returned in error .
Sourcepub unsafe fn initWithData_options_error(
this: Allocated<Self>,
data: &NSData,
mask: NSXMLNodeOptions,
) -> Result<Retained<Self>, Retained<NSError>>
Available on crate features NSData
and NSError
and NSXMLNodeOptions
only.
pub unsafe fn initWithData_options_error( this: Allocated<Self>, data: &NSData, mask: NSXMLNodeOptions, ) -> Result<Retained<Self>, Retained<NSError>>
NSData
and NSError
and NSXMLNodeOptions
only.Returns a document created from data. Parse errors are returned in error .
Sourcepub unsafe fn initWithRootElement(
this: Allocated<Self>,
element: Option<&NSXMLElement>,
) -> Retained<Self>
Available on crate feature NSXMLElement
only.
pub unsafe fn initWithRootElement( this: Allocated<Self>, element: Option<&NSXMLElement>, ) -> Retained<Self>
NSXMLElement
only.Returns a document with a single child, the root element.
pub unsafe fn replacementClassForClass(cls: &AnyClass) -> &'static AnyClass
Sourcepub unsafe fn characterEncoding(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn characterEncoding(&self) -> Option<Retained<NSString>>
NSString
only.Sets the character encoding to an IANA type.
Sourcepub unsafe fn setCharacterEncoding(&self, character_encoding: Option<&NSString>)
Available on crate feature NSString
only.
pub unsafe fn setCharacterEncoding(&self, character_encoding: Option<&NSString>)
NSString
only.Setter for characterEncoding
.
Sourcepub unsafe fn version(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn version(&self) -> Option<Retained<NSString>>
NSString
only.Sets the XML version. Should be 1.0 or 1.1.
Sourcepub unsafe fn setVersion(&self, version: Option<&NSString>)
Available on crate feature NSString
only.
pub unsafe fn setVersion(&self, version: Option<&NSString>)
NSString
only.Setter for version
.
Sourcepub unsafe fn isStandalone(&self) -> bool
pub unsafe fn isStandalone(&self) -> bool
Set whether this document depends on an external DTD. If this option is set the standalone declaration will appear on output.
Sourcepub unsafe fn setStandalone(&self, standalone: bool)
pub unsafe fn setStandalone(&self, standalone: bool)
Setter for isStandalone
.
Sourcepub unsafe fn documentContentKind(&self) -> NSXMLDocumentContentKind
pub unsafe fn documentContentKind(&self) -> NSXMLDocumentContentKind
The kind of document.
Sourcepub unsafe fn setDocumentContentKind(
&self,
document_content_kind: NSXMLDocumentContentKind,
)
pub unsafe fn setDocumentContentKind( &self, document_content_kind: NSXMLDocumentContentKind, )
Setter for documentContentKind
.
Sourcepub unsafe fn MIMEType(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn MIMEType(&self) -> Option<Retained<NSString>>
NSString
only.Set the MIME type, eg text/xml.
Sourcepub unsafe fn setMIMEType(&self, mime_type: Option<&NSString>)
Available on crate feature NSString
only.
pub unsafe fn setMIMEType(&self, mime_type: Option<&NSString>)
NSString
only.Setter for MIMEType
.
Sourcepub unsafe fn DTD(&self) -> Option<Retained<NSXMLDTD>>
Available on crate feature NSXMLDTD
only.
pub unsafe fn DTD(&self) -> Option<Retained<NSXMLDTD>>
NSXMLDTD
only.Set the associated DTD. This DTD will be output with the document.
Sourcepub unsafe fn setDTD(&self, dtd: Option<&NSXMLDTD>)
Available on crate feature NSXMLDTD
only.
pub unsafe fn setDTD(&self, dtd: Option<&NSXMLDTD>)
NSXMLDTD
only.Setter for DTD
.
Sourcepub unsafe fn setRootElement(&self, root: &NSXMLElement)
Available on crate feature NSXMLElement
only.
pub unsafe fn setRootElement(&self, root: &NSXMLElement)
NSXMLElement
only.Set the root element. Removes all other children including comments and processing-instructions.
Sourcepub unsafe fn rootElement(&self) -> Option<Retained<NSXMLElement>>
Available on crate feature NSXMLElement
only.
pub unsafe fn rootElement(&self) -> Option<Retained<NSXMLElement>>
NSXMLElement
only.The root element.
Sourcepub unsafe fn insertChild_atIndex(&self, child: &NSXMLNode, index: NSUInteger)
pub unsafe fn insertChild_atIndex(&self, child: &NSXMLNode, index: NSUInteger)
Inserts a child at a particular index.
Sourcepub unsafe fn insertChildren_atIndex(
&self,
children: &NSArray<NSXMLNode>,
index: NSUInteger,
)
Available on crate feature NSArray
only.
pub unsafe fn insertChildren_atIndex( &self, children: &NSArray<NSXMLNode>, index: NSUInteger, )
NSArray
only.Insert several children at a particular index.
Sourcepub unsafe fn removeChildAtIndex(&self, index: NSUInteger)
pub unsafe fn removeChildAtIndex(&self, index: NSUInteger)
Removes a child at a particular index.
Sourcepub unsafe fn setChildren(&self, children: Option<&NSArray<NSXMLNode>>)
Available on crate feature NSArray
only.
pub unsafe fn setChildren(&self, children: Option<&NSArray<NSXMLNode>>)
NSArray
only.Removes all existing children and replaces them with the new children. Set children to nil to simply remove all children.
Sourcepub unsafe fn addChild(&self, child: &NSXMLNode)
pub unsafe fn addChild(&self, child: &NSXMLNode)
Adds a child to the end of the existing children.
Sourcepub unsafe fn replaceChildAtIndex_withNode(
&self,
index: NSUInteger,
node: &NSXMLNode,
)
pub unsafe fn replaceChildAtIndex_withNode( &self, index: NSUInteger, node: &NSXMLNode, )
Replaces a child at a particular index with another child.
Sourcepub unsafe fn XMLData(&self) -> Retained<NSData>
Available on crate feature NSData
only.
pub unsafe fn XMLData(&self) -> Retained<NSData>
NSData
only.Invokes XMLDataWithOptions with NSXMLNodeOptionsNone.
Sourcepub unsafe fn XMLDataWithOptions(
&self,
options: NSXMLNodeOptions,
) -> Retained<NSData>
Available on crate features NSData
and NSXMLNodeOptions
only.
pub unsafe fn XMLDataWithOptions( &self, options: NSXMLNodeOptions, ) -> Retained<NSData>
NSData
and NSXMLNodeOptions
only.The representation of this node as it would appear in an XML document, encoded based on characterEncoding.
Sourcepub unsafe fn objectByApplyingXSLT_arguments_error(
&self,
xslt: &NSData,
arguments: Option<&NSDictionary<NSString, NSString>>,
) -> Result<Retained<AnyObject>, Retained<NSError>>
Available on crate features NSData
and NSDictionary
and NSError
and NSString
only.
pub unsafe fn objectByApplyingXSLT_arguments_error( &self, xslt: &NSData, arguments: Option<&NSDictionary<NSString, NSString>>, ) -> Result<Retained<AnyObject>, Retained<NSError>>
NSData
and NSDictionary
and NSError
and NSString
only.Applies XSLT with arguments (NSString key/value pairs) to this document, returning a new document.
Sourcepub unsafe fn objectByApplyingXSLTString_arguments_error(
&self,
xslt: &NSString,
arguments: Option<&NSDictionary<NSString, NSString>>,
) -> Result<Retained<AnyObject>, Retained<NSError>>
Available on crate features NSDictionary
and NSError
and NSString
only.
pub unsafe fn objectByApplyingXSLTString_arguments_error( &self, xslt: &NSString, arguments: Option<&NSDictionary<NSString, NSString>>, ) -> Result<Retained<AnyObject>, Retained<NSError>>
NSDictionary
and NSError
and NSString
only.Applies XSLT as expressed by a string with arguments (NSString key/value pairs) to this document, returning a new document.
Sourcepub unsafe fn objectByApplyingXSLTAtURL_arguments_error(
&self,
xslt_url: &NSURL,
argument: Option<&NSDictionary<NSString, NSString>>,
) -> Result<Retained<AnyObject>, Retained<NSError>>
Available on crate features NSDictionary
and NSError
and NSString
and NSURL
only.
pub unsafe fn objectByApplyingXSLTAtURL_arguments_error( &self, xslt_url: &NSURL, argument: Option<&NSDictionary<NSString, NSString>>, ) -> Result<Retained<AnyObject>, Retained<NSError>>
NSDictionary
and NSError
and NSString
and NSURL
only.Applies the XSLT at a URL with arguments (NSString key/value pairs) to this document, returning a new document. Error may contain a connection error from the URL.
pub unsafe fn validateAndReturnError(&self) -> Result<(), Retained<NSError>>
NSError
only.Source§impl NSXMLDocument
Methods declared on superclass NSXMLNode
.
impl NSXMLDocument
Methods declared on superclass NSXMLNode
.
Sourcepub unsafe fn initWithKind(
this: Allocated<Self>,
kind: NSXMLNodeKind,
) -> Retained<Self>
pub unsafe fn initWithKind( this: Allocated<Self>, kind: NSXMLNodeKind, ) -> Retained<Self>
Invokes
initWithKind:options:
with options set to NSXMLNodeOptionsNone
Sourcepub unsafe fn initWithKind_options(
this: Allocated<Self>,
kind: NSXMLNodeKind,
options: NSXMLNodeOptions,
) -> Retained<Self>
Available on crate feature NSXMLNodeOptions
only.
pub unsafe fn initWithKind_options( this: Allocated<Self>, kind: NSXMLNodeKind, options: NSXMLNodeOptions, ) -> Retained<Self>
NSXMLNodeOptions
only.Inits a node with fidelity options as description NSXMLNodeOptions.h
Methods from Deref<Target = NSXMLNode>§
Sourcepub unsafe fn kind(&self) -> NSXMLNodeKind
pub unsafe fn kind(&self) -> NSXMLNodeKind
Returns an element, attribute, entity, or notation DTD node based on the full XML string.
Sourcepub unsafe fn name(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn name(&self) -> Option<Retained<NSString>>
NSString
only.Sets the nodes name. Applicable for element, attribute, namespace, processing-instruction, document type declaration, element declaration, attribute declaration, entity declaration, and notation declaration.
Sourcepub unsafe fn setName(&self, name: Option<&NSString>)
Available on crate feature NSString
only.
pub unsafe fn setName(&self, name: Option<&NSString>)
NSString
only.Setter for name
.
Sourcepub unsafe fn objectValue(&self) -> Option<Retained<AnyObject>>
pub unsafe fn objectValue(&self) -> Option<Retained<AnyObject>>
Sets the content of the node. Setting the objectValue removes all existing children including processing instructions and comments. Setting the object value on an element creates a single text node child.
Sourcepub unsafe fn setObjectValue(&self, object_value: Option<&AnyObject>)
pub unsafe fn setObjectValue(&self, object_value: Option<&AnyObject>)
Setter for objectValue
.
Sourcepub unsafe fn stringValue(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn stringValue(&self) -> Option<Retained<NSString>>
NSString
only.Sets the content of the node. Setting the stringValue removes all existing children including processing instructions and comments. Setting the string value on an element creates a single text node child. The getter returns the string value of the node, which may be either its content or child text nodes, depending on the type of node. Elements are recursed and text nodes concatenated in document order with no intervening spaces.
Sourcepub unsafe fn setStringValue(&self, string_value: Option<&NSString>)
Available on crate feature NSString
only.
pub unsafe fn setStringValue(&self, string_value: Option<&NSString>)
NSString
only.Setter for stringValue
.
Sourcepub unsafe fn setStringValue_resolvingEntities(
&self,
string: &NSString,
resolve: bool,
)
Available on crate feature NSString
only.
pub unsafe fn setStringValue_resolvingEntities( &self, string: &NSString, resolve: bool, )
NSString
only.Sets the content as with
setStringValue:
, but when “resolve” is true, character references, predefined entities and user entities available in the document’s dtd are resolved. Entities not available in the dtd remain in their entity form.
Sourcepub unsafe fn index(&self) -> NSUInteger
pub unsafe fn index(&self) -> NSUInteger
A node’s index amongst its siblings.
Sourcepub unsafe fn level(&self) -> NSUInteger
pub unsafe fn level(&self) -> NSUInteger
The depth of the node within the tree. Documents and standalone nodes are level 0.
Sourcepub unsafe fn rootDocument(&self) -> Option<Retained<NSXMLDocument>>
pub unsafe fn rootDocument(&self) -> Option<Retained<NSXMLDocument>>
The encompassing document or nil.
Sourcepub unsafe fn parent(&self) -> Option<Retained<NSXMLNode>>
pub unsafe fn parent(&self) -> Option<Retained<NSXMLNode>>
The parent of this node. Documents and standalone Nodes have a nil parent; there is not a 1-to-1 relationship between parent and children, eg a namespace cannot be a child but has a parent element.
Sourcepub unsafe fn childCount(&self) -> NSUInteger
pub unsafe fn childCount(&self) -> NSUInteger
The amount of children, relevant for documents, elements, and document type declarations. Use this instead of [[self children] count].
Sourcepub unsafe fn children(&self) -> Option<Retained<NSArray<NSXMLNode>>>
Available on crate feature NSArray
only.
pub unsafe fn children(&self) -> Option<Retained<NSArray<NSXMLNode>>>
NSArray
only.An immutable array of child nodes. Relevant for documents, elements, and document type declarations.
Sourcepub unsafe fn childAtIndex(
&self,
index: NSUInteger,
) -> Option<Retained<NSXMLNode>>
pub unsafe fn childAtIndex( &self, index: NSUInteger, ) -> Option<Retained<NSXMLNode>>
Returns the child node at a particular index.
Sourcepub unsafe fn previousSibling(&self) -> Option<Retained<NSXMLNode>>
pub unsafe fn previousSibling(&self) -> Option<Retained<NSXMLNode>>
Returns the previous sibling, or nil if there isn’t one.
Sourcepub unsafe fn nextSibling(&self) -> Option<Retained<NSXMLNode>>
pub unsafe fn nextSibling(&self) -> Option<Retained<NSXMLNode>>
Returns the next sibling, or nil if there isn’t one.
Sourcepub unsafe fn previousNode(&self) -> Option<Retained<NSXMLNode>>
pub unsafe fn previousNode(&self) -> Option<Retained<NSXMLNode>>
Returns the previous node in document order. This can be used to walk the tree backwards.
Sourcepub unsafe fn nextNode(&self) -> Option<Retained<NSXMLNode>>
pub unsafe fn nextNode(&self) -> Option<Retained<NSXMLNode>>
Returns the next node in document order. This can be used to walk the tree forwards.
Sourcepub unsafe fn XPath(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn XPath(&self) -> Option<Retained<NSString>>
NSString
only.Returns the XPath to this node, for example foo/bar[2]/baz.
Sourcepub unsafe fn localName(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn localName(&self) -> Option<Retained<NSString>>
NSString
only.Returns the local name bar if this attribute or element’s name is foo:bar
Sourcepub unsafe fn prefix(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn prefix(&self) -> Option<Retained<NSString>>
NSString
only.Returns the prefix foo if this attribute or element’s name if foo:bar
Sourcepub unsafe fn URI(&self) -> Option<Retained<NSString>>
Available on crate feature NSString
only.
pub unsafe fn URI(&self) -> Option<Retained<NSString>>
NSString
only.Set the URI of this element, attribute, or document. For documents it is the URI of document origin. Getter returns the URI of this element, attribute, or document. For documents it is the URI of document origin and is automatically set when using initWithContentsOfURL.
Sourcepub unsafe fn setURI(&self, uri: Option<&NSString>)
Available on crate feature NSString
only.
pub unsafe fn setURI(&self, uri: Option<&NSString>)
NSString
only.Setter for URI
.
Sourcepub unsafe fn description(&self) -> Retained<NSString>
Available on crate feature NSString
only.
pub unsafe fn description(&self) -> Retained<NSString>
NSString
only.Used for debugging. May give more information than XMLString.
Sourcepub unsafe fn XMLString(&self) -> Retained<NSString>
Available on crate feature NSString
only.
pub unsafe fn XMLString(&self) -> Retained<NSString>
NSString
only.The representation of this node as it would appear in an XML document.
Sourcepub unsafe fn XMLStringWithOptions(
&self,
options: NSXMLNodeOptions,
) -> Retained<NSString>
Available on crate features NSString
and NSXMLNodeOptions
only.
pub unsafe fn XMLStringWithOptions( &self, options: NSXMLNodeOptions, ) -> Retained<NSString>
NSString
and NSXMLNodeOptions
only.The representation of this node as it would appear in an XML document, with various output options available.
Sourcepub unsafe fn canonicalXMLStringPreservingComments(
&self,
comments: bool,
) -> Retained<NSString>
Available on crate feature NSString
only.
pub unsafe fn canonicalXMLStringPreservingComments( &self, comments: bool, ) -> Retained<NSString>
NSString
only.W3 canonical form (http://www.w3.org/TR/xml-c14n). The input option NSXMLNodePreserveWhitespace should be set for true canonical form.
Sourcepub unsafe fn nodesForXPath_error(
&self,
xpath: &NSString,
) -> Result<Retained<NSArray<NSXMLNode>>, Retained<NSError>>
Available on crate features NSArray
and NSError
and NSString
only.
pub unsafe fn nodesForXPath_error( &self, xpath: &NSString, ) -> Result<Retained<NSArray<NSXMLNode>>, Retained<NSError>>
NSArray
and NSError
and NSString
only.Returns the nodes resulting from applying an XPath to this node using the node as the context item (“.”). normalizeAdjacentTextNodesPreservingCDATA:NO should be called if there are adjacent text nodes since they are not allowed under the XPath/XQuery Data Model.
Returns: An array whose elements are a kind of NSXMLNode.
Sourcepub unsafe fn objectsForXQuery_constants_error(
&self,
xquery: &NSString,
constants: Option<&NSDictionary<NSString, AnyObject>>,
) -> Result<Retained<NSArray>, Retained<NSError>>
Available on crate features NSArray
and NSDictionary
and NSError
and NSString
only.
pub unsafe fn objectsForXQuery_constants_error( &self, xquery: &NSString, constants: Option<&NSDictionary<NSString, AnyObject>>, ) -> Result<Retained<NSArray>, Retained<NSError>>
NSArray
and NSDictionary
and NSError
and NSString
only.Returns the objects resulting from applying an XQuery to this node using the node as the context item (“.”). Constants are a name-value dictionary for constants declared “external” in the query. normalizeAdjacentTextNodesPreservingCDATA:NO should be called if there are adjacent text nodes since they are not allowed under the XPath/XQuery Data Model.
Returns: An array whose elements are kinds of NSArray, NSData, NSDate, NSNumber, NSString, NSURL, or NSXMLNode.
pub unsafe fn objectsForXQuery_error( &self, xquery: &NSString, ) -> Result<Retained<NSArray>, Retained<NSError>>
NSArray
and NSError
and NSString
only.Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init
/new
methods).
§Example
Check that an instance of NSObject
has the precise class NSObject
.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load
instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.Use Ivar::load
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T
.
This is the reference-variant. Use Retained::downcast
if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString
.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString
to a NSMutableString
,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass:
for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject
.
§Panics
This works internally by calling isKindOfClass:
. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject
and
NSProxy
implement this method.
§Examples
Cast an NSString
back and forth from NSObject
.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();
Try (and fail) to cast an NSObject
to an NSString
.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());
Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();
This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}
Trait Implementations§
Source§impl AsRef<AnyObject> for NSXMLDocument
impl AsRef<AnyObject> for NSXMLDocument
Source§impl AsRef<NSObject> for NSXMLDocument
impl AsRef<NSObject> for NSXMLDocument
Source§impl AsRef<NSXMLDocument> for NSXMLDocument
impl AsRef<NSXMLDocument> for NSXMLDocument
Source§impl AsRef<NSXMLNode> for NSXMLDocument
impl AsRef<NSXMLNode> for NSXMLDocument
Source§impl Borrow<AnyObject> for NSXMLDocument
impl Borrow<AnyObject> for NSXMLDocument
Source§impl Borrow<NSObject> for NSXMLDocument
impl Borrow<NSObject> for NSXMLDocument
Source§impl Borrow<NSXMLNode> for NSXMLDocument
impl Borrow<NSXMLNode> for NSXMLDocument
Source§impl ClassType for NSXMLDocument
impl ClassType for NSXMLDocument
Source§const NAME: &'static str = "NSXMLDocument"
const NAME: &'static str = "NSXMLDocument"
Source§type ThreadKind = <<NSXMLDocument as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSXMLDocument as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for NSXMLDocument
Available on crate feature NSObject
only.
impl CopyingHelper for NSXMLDocument
NSObject
only.Source§type Result = NSXMLDocument
type Result = NSXMLDocument
Self
if the type has no
immutable counterpart. Read moreSource§impl Debug for NSXMLDocument
impl Debug for NSXMLDocument
Source§impl Deref for NSXMLDocument
impl Deref for NSXMLDocument
Source§impl Hash for NSXMLDocument
impl Hash for NSXMLDocument
Source§impl Message for NSXMLDocument
impl Message for NSXMLDocument
Source§impl NSCopying for NSXMLDocument
impl NSCopying for NSXMLDocument
Source§impl NSObjectProtocol for NSXMLDocument
impl NSObjectProtocol for NSXMLDocument
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass
directly, or cast your objects with AnyObject::downcast_ref