pub struct NSURL { /* private fields */ }
NSURL
only.Expand description
Implementations§
Source§impl NSURL
impl NSURL
pub fn initWithScheme_host_path( this: Allocated<Self>, scheme: &NSString, host: Option<&NSString>, path: &NSString, ) -> Option<Retained<Self>>
NSString
only.pub fn initFileURLWithPath_isDirectory_relativeToURL( this: Allocated<Self>, path: &NSString, is_dir: bool, base_url: Option<&NSURL>, ) -> Retained<Self>
NSString
only.pub fn initFileURLWithPath_relativeToURL( this: Allocated<Self>, path: &NSString, base_url: Option<&NSURL>, ) -> Retained<Self>
NSString
only.pub fn initFileURLWithPath_isDirectory( this: Allocated<Self>, path: &NSString, is_dir: bool, ) -> Retained<Self>
NSString
only.pub fn initFileURLWithPath( this: Allocated<Self>, path: &NSString, ) -> Retained<Self>
NSString
only.pub fn fileURLWithPath_isDirectory_relativeToURL( path: &NSString, is_dir: bool, base_url: Option<&NSURL>, ) -> Retained<NSURL>
NSString
only.pub fn fileURLWithPath_relativeToURL( path: &NSString, base_url: Option<&NSURL>, ) -> Retained<NSURL>
NSString
only.pub fn fileURLWithPath_isDirectory( path: &NSString, is_dir: bool, ) -> Retained<NSURL>
NSString
only.pub fn fileURLWithPath(path: &NSString) -> Retained<NSURL>
NSString
only.Sourcepub unsafe fn initFileURLWithFileSystemRepresentation_isDirectory_relativeToURL(
this: Allocated<Self>,
path: NonNull<c_char>,
is_dir: bool,
base_url: Option<&NSURL>,
) -> Retained<Self>
pub unsafe fn initFileURLWithFileSystemRepresentation_isDirectory_relativeToURL( this: Allocated<Self>, path: NonNull<c_char>, is_dir: bool, base_url: Option<&NSURL>, ) -> Retained<Self>
§Safety
path
must be a valid pointer.
Sourcepub unsafe fn fileURLWithFileSystemRepresentation_isDirectory_relativeToURL(
path: NonNull<c_char>,
is_dir: bool,
base_url: Option<&NSURL>,
) -> Retained<NSURL>
pub unsafe fn fileURLWithFileSystemRepresentation_isDirectory_relativeToURL( path: NonNull<c_char>, is_dir: bool, base_url: Option<&NSURL>, ) -> Retained<NSURL>
§Safety
path
must be a valid pointer.
pub fn initWithString( this: Allocated<Self>, url_string: &NSString, ) -> Option<Retained<Self>>
NSString
only.pub fn initWithString_relativeToURL( this: Allocated<Self>, url_string: &NSString, base_url: Option<&NSURL>, ) -> Option<Retained<Self>>
NSString
only.pub fn URLWithString(url_string: &NSString) -> Option<Retained<Self>>
NSString
only.pub fn URLWithString_relativeToURL( url_string: &NSString, base_url: Option<&NSURL>, ) -> Option<Retained<Self>>
NSString
only.Sourcepub fn initWithString_encodingInvalidCharacters(
this: Allocated<Self>,
url_string: &NSString,
encoding_invalid_characters: bool,
) -> Option<Retained<Self>>
Available on crate feature NSString
only.
pub fn initWithString_encodingInvalidCharacters( this: Allocated<Self>, url_string: &NSString, encoding_invalid_characters: bool, ) -> Option<Retained<Self>>
NSString
only.Initializes an NSURL
with a URL string and the option to add (or skip) IDNA- and percent-encoding of invalid characters.
If encodingInvalidCharacters
is false, and the URL string is invalid according to RFC 3986, nil
is returned.
If encodingInvalidCharacters
is true, NSURL
will try to encode the string to create a valid URL.
If the URL string is still invalid after encoding, nil
is returned.
- Parameter URLString: The URL string.
- Parameter encodingInvalidCharacters: True if
NSURL
should try to encode an invalid URL string, false otherwise. - Returns: An
NSURL
instance for a valid URL, ornil
if the URL is invalid.
Sourcepub fn URLWithString_encodingInvalidCharacters(
url_string: &NSString,
encoding_invalid_characters: bool,
) -> Option<Retained<Self>>
Available on crate feature NSString
only.
pub fn URLWithString_encodingInvalidCharacters( url_string: &NSString, encoding_invalid_characters: bool, ) -> Option<Retained<Self>>
NSString
only.Initializes and returns a newly created NSURL
with a URL string and the option to add (or skip) IDNA- and percent-encoding of invalid characters.
If encodingInvalidCharacters
is false, and the URL string is invalid according to RFC 3986, nil
is returned.
If encodingInvalidCharacters
is true, NSURL
will try to encode the string to create a valid URL.
If the URL string is still invalid after encoding, nil
is returned.
- Parameter URLString: The URL string.
- Parameter encodingInvalidCharacters: True if
NSURL
should try to encode an invalid URL string, false otherwise. - Returns: An
NSURL
instance for a valid URL, ornil
if the URL is invalid.
pub fn initWithDataRepresentation_relativeToURL( this: Allocated<Self>, data: &NSData, base_url: Option<&NSURL>, ) -> Retained<Self>
NSData
only.pub fn URLWithDataRepresentation_relativeToURL( data: &NSData, base_url: Option<&NSURL>, ) -> Retained<NSURL>
NSData
only.pub fn initAbsoluteURLWithDataRepresentation_relativeToURL( this: Allocated<Self>, data: &NSData, base_url: Option<&NSURL>, ) -> Retained<Self>
NSData
only.pub fn absoluteURLWithDataRepresentation_relativeToURL( data: &NSData, base_url: Option<&NSURL>, ) -> Retained<NSURL>
NSData
only.pub fn dataRepresentation(&self) -> Retained<NSData>
NSData
only.pub fn absoluteString(&self) -> Option<Retained<NSString>>
NSString
only.pub fn relativeString(&self) -> Retained<NSString>
NSString
only.pub fn baseURL(&self) -> Option<Retained<NSURL>>
pub fn absoluteURL(&self) -> Option<Retained<NSURL>>
pub fn scheme(&self) -> Option<Retained<NSString>>
NSString
only.pub fn resourceSpecifier(&self) -> Option<Retained<NSString>>
NSString
only.pub fn host(&self) -> Option<Retained<NSString>>
NSString
only.pub fn port(&self) -> Option<Retained<NSNumber>>
NSValue
only.pub fn user(&self) -> Option<Retained<NSString>>
NSString
only.pub fn password(&self) -> Option<Retained<NSString>>
NSString
only.pub fn path(&self) -> Option<Retained<NSString>>
NSString
only.pub fn fragment(&self) -> Option<Retained<NSString>>
NSString
only.pub fn parameterString(&self) -> Option<Retained<NSString>>
NSString
only.pub fn query(&self) -> Option<Retained<NSString>>
NSString
only.pub fn relativePath(&self) -> Option<Retained<NSString>>
NSString
only.pub fn hasDirectoryPath(&self) -> bool
Sourcepub unsafe fn getFileSystemRepresentation_maxLength(
&self,
buffer: NonNull<c_char>,
max_buffer_length: NSUInteger,
) -> bool
pub unsafe fn getFileSystemRepresentation_maxLength( &self, buffer: NonNull<c_char>, max_buffer_length: NSUInteger, ) -> bool
§Safety
buffer
must be a valid pointer.
pub fn fileSystemRepresentation(&self) -> NonNull<c_char>
pub fn isFileURL(&self) -> bool
pub fn standardizedURL(&self) -> Option<Retained<NSURL>>
pub fn isFileReferenceURL(&self) -> bool
pub fn fileReferenceURL(&self) -> Option<Retained<NSURL>>
pub fn filePathURL(&self) -> Option<Retained<NSURL>>
Sourcepub unsafe fn getResourceValue_forKey_error(
&self,
value: &mut Option<Retained<AnyObject>>,
key: &NSURLResourceKey,
) -> Result<(), Retained<NSError>>
Available on crate features NSError
and NSString
only.
pub unsafe fn getResourceValue_forKey_error( &self, value: &mut Option<Retained<AnyObject>>, key: &NSURLResourceKey, ) -> Result<(), Retained<NSError>>
NSError
and NSString
only.§Safety
value
should be of the correct type.
pub fn resourceValuesForKeys_error( &self, keys: &NSArray<NSURLResourceKey>, ) -> Result<Retained<NSDictionary<NSURLResourceKey, AnyObject>>, Retained<NSError>>
NSArray
and NSDictionary
and NSError
and NSString
only.Sourcepub unsafe fn setResourceValue_forKey_error(
&self,
value: Option<&AnyObject>,
key: &NSURLResourceKey,
) -> Result<(), Retained<NSError>>
Available on crate features NSError
and NSString
only.
pub unsafe fn setResourceValue_forKey_error( &self, value: Option<&AnyObject>, key: &NSURLResourceKey, ) -> Result<(), Retained<NSError>>
NSError
and NSString
only.§Safety
value
should be of the correct type.
Sourcepub unsafe fn setResourceValues_error(
&self,
keyed_values: &NSDictionary<NSURLResourceKey, AnyObject>,
) -> Result<(), Retained<NSError>>
Available on crate features NSDictionary
and NSError
and NSString
only.
pub unsafe fn setResourceValues_error( &self, keyed_values: &NSDictionary<NSURLResourceKey, AnyObject>, ) -> Result<(), Retained<NSError>>
NSDictionary
and NSError
and NSString
only.§Safety
keyed_values
generic should be of the correct type.
pub fn removeCachedResourceValueForKey(&self, key: &NSURLResourceKey)
NSString
only.pub fn removeAllCachedResourceValues(&self)
Sourcepub unsafe fn setTemporaryResourceValue_forKey(
&self,
value: Option<&AnyObject>,
key: &NSURLResourceKey,
)
Available on crate feature NSString
only.
pub unsafe fn setTemporaryResourceValue_forKey( &self, value: Option<&AnyObject>, key: &NSURLResourceKey, )
NSString
only.§Safety
value
should be of the correct type.
pub fn bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error( &self, options: NSURLBookmarkCreationOptions, keys: Option<&NSArray<NSURLResourceKey>>, relative_url: Option<&NSURL>, ) -> Result<Retained<NSData>, Retained<NSError>>
NSArray
and NSData
and NSError
and NSString
only.Sourcepub unsafe fn initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error(
this: Allocated<Self>,
bookmark_data: &NSData,
options: NSURLBookmarkResolutionOptions,
relative_url: Option<&NSURL>,
is_stale: *mut Bool,
) -> Result<Retained<Self>, Retained<NSError>>
Available on crate features NSData
and NSError
only.
pub unsafe fn initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error( this: Allocated<Self>, bookmark_data: &NSData, options: NSURLBookmarkResolutionOptions, relative_url: Option<&NSURL>, is_stale: *mut Bool, ) -> Result<Retained<Self>, Retained<NSError>>
NSData
and NSError
only.§Safety
is_stale
must be a valid pointer or null.
Sourcepub unsafe fn URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error(
bookmark_data: &NSData,
options: NSURLBookmarkResolutionOptions,
relative_url: Option<&NSURL>,
is_stale: *mut Bool,
) -> Result<Retained<Self>, Retained<NSError>>
Available on crate features NSData
and NSError
only.
pub unsafe fn URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error( bookmark_data: &NSData, options: NSURLBookmarkResolutionOptions, relative_url: Option<&NSURL>, is_stale: *mut Bool, ) -> Result<Retained<Self>, Retained<NSError>>
NSData
and NSError
only.§Safety
is_stale
must be a valid pointer or null.
pub fn resourceValuesForKeys_fromBookmarkData( keys: &NSArray<NSURLResourceKey>, bookmark_data: &NSData, ) -> Option<Retained<NSDictionary<NSURLResourceKey, AnyObject>>>
NSArray
and NSData
and NSDictionary
and NSString
only.pub fn writeBookmarkData_toURL_options_error( bookmark_data: &NSData, bookmark_file_url: &NSURL, options: NSURLBookmarkFileCreationOptions, ) -> Result<(), Retained<NSError>>
NSData
and NSError
only.pub fn bookmarkDataWithContentsOfURL_error( bookmark_file_url: &NSURL, ) -> Result<Retained<NSData>, Retained<NSError>>
NSData
and NSError
only.pub fn URLByResolvingAliasFileAtURL_options_error( url: &NSURL, options: NSURLBookmarkResolutionOptions, ) -> Result<Retained<Self>, Retained<NSError>>
NSError
only.pub unsafe fn startAccessingSecurityScopedResource(&self) -> bool
pub unsafe fn stopAccessingSecurityScopedResource(&self)
Source§impl NSURL
NSPromisedItems.
impl NSURL
NSPromisedItems.
Sourcepub unsafe fn getPromisedItemResourceValue_forKey_error(
&self,
value: &mut Option<Retained<AnyObject>>,
key: &NSURLResourceKey,
) -> Result<(), Retained<NSError>>
Available on crate features NSError
and NSString
only.
pub unsafe fn getPromisedItemResourceValue_forKey_error( &self, value: &mut Option<Retained<AnyObject>>, key: &NSURLResourceKey, ) -> Result<(), Retained<NSError>>
NSError
and NSString
only.§Safety
value
should be of the correct type.
pub fn promisedItemResourceValuesForKeys_error( &self, keys: &NSArray<NSURLResourceKey>, ) -> Result<Retained<NSDictionary<NSURLResourceKey, AnyObject>>, Retained<NSError>>
NSArray
and NSDictionary
and NSError
and NSString
only.pub fn checkPromisedItemIsReachableAndReturnError( &self, ) -> Result<(), Retained<NSError>>
NSError
only.impl NSURL
NSItemProvider.
Source§impl NSURL
NSURLPathUtilities.
impl NSURL
NSURLPathUtilities.
pub fn fileURLWithPathComponents( components: &NSArray<NSString>, ) -> Option<Retained<NSURL>>
NSArray
and NSString
only.pub fn pathComponents(&self) -> Option<Retained<NSArray<NSString>>>
NSArray
and NSString
only.pub fn lastPathComponent(&self) -> Option<Retained<NSString>>
NSString
only.pub fn pathExtension(&self) -> Option<Retained<NSString>>
NSString
only.pub fn URLByAppendingPathComponent( &self, path_component: &NSString, ) -> Option<Retained<NSURL>>
NSString
only.pub fn URLByAppendingPathComponent_isDirectory( &self, path_component: &NSString, is_directory: bool, ) -> Option<Retained<NSURL>>
NSString
only.pub fn URLByDeletingLastPathComponent(&self) -> Option<Retained<NSURL>>
pub fn URLByAppendingPathExtension( &self, path_extension: &NSString, ) -> Option<Retained<NSURL>>
NSString
only.pub fn URLByDeletingPathExtension(&self) -> Option<Retained<NSURL>>
pub fn checkResourceIsReachableAndReturnError( &self, ) -> Result<(), Retained<NSError>>
NSError
only.pub fn URLByStandardizingPath(&self) -> Option<Retained<NSURL>>
pub fn URLByResolvingSymlinksInPath(&self) -> Option<Retained<NSURL>>
Source§impl NSURL
NSURLLoading.
impl NSURL
NSURLLoading.
pub fn resourceDataUsingCache( &self, should_use_cache: bool, ) -> Option<Retained<NSData>>
NSData
only.Sourcepub unsafe fn loadResourceDataNotifyingClient_usingCache(
&self,
client: &AnyObject,
should_use_cache: bool,
)
👎Deprecated: Use NSURLConnection instead
pub unsafe fn loadResourceDataNotifyingClient_usingCache( &self, client: &AnyObject, should_use_cache: bool, )
§Safety
client
should be of the correct type.
pub fn propertyForKey( &self, property_key: &NSString, ) -> Option<Retained<AnyObject>>
NSString
only.pub fn setResourceData(&self, data: &NSData) -> bool
NSData
only.Sourcepub unsafe fn setProperty_forKey(
&self,
property: &AnyObject,
property_key: &NSString,
) -> bool
👎Deprecated: Use NSURLConnection insteadAvailable on crate feature NSString
only.
pub unsafe fn setProperty_forKey( &self, property: &AnyObject, property_key: &NSString, ) -> bool
NSString
only.§Safety
property
should be of the correct type.
pub fn URLHandleUsingCache( &self, should_use_cache: bool, ) -> Option<Retained<NSURLHandle>>
NSURLHandle
only.Source§impl NSURL
Path
conversion.
impl NSURL
Path
conversion.
pub fn from_path( path: &Path, is_directory: bool, base_url: Option<&NSURL>, ) -> Option<Retained<Self>>
std
and Unix and non-crate feature gnustep-1-7
only.Sourcepub fn from_file_path<P: AsRef<Path>>(path: P) -> Option<Retained<Self>>
Available on crate feature std
and Unix and non-crate feature gnustep-1-7
only.
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Option<Retained<Self>>
std
and Unix and non-crate feature gnustep-1-7
only.Create a file url from a Path
.
If the path is relative, it will be considered relative to the current directory.
Returns None
when given an invalid path (such as a path containing
interior NUL bytes). The exact checks are not guaranteed.
§Non-unicode and HFS+ support
Modern Apple disk drives use APFS nowadays, which forces all paths to
be valid unicode. The URL standard also uses unicode, and non-unicode
parts of the URL will be percent-encoded, and the url will be given
the scheme file://
. All of this is as it should be.
Unfortunately, a lot of Foundation APIs (including the NSFileManager
and NSData
APIs) currently assume that they can always get unicode
paths back by calling NSURL::path
internally, which is not true.
If you need to support non-unicode paths in HFS+ with these APIs, you
can work around this issue by percent-encoding any non-unicode parts
of the path yourself beforehand, similar to what’s done in the
trash-rs
crate.
(this function cannot do that for you, since it relies on a quirk of
HFS+ that b“\xf8“ and b“%F8“ refer to the same file).
§Examples
use std::path::Path;
use objc2_foundation::NSURL;
// Absolute paths work as you'd expect.
let url = NSURL::from_file_path("/tmp/file.txt").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/tmp/file.txt"));
// Relative paths are relative to the current directory.
let url = NSURL::from_file_path("foo.txt").unwrap();
assert_eq!(url.to_file_path().unwrap(), std::env::current_dir().unwrap().join("foo.txt"));
// Some invalid paths return `None`.
assert!(NSURL::from_file_path("").is_none());
// Another example of an invalid path containing interior NUL bytes.
assert!(NSURL::from_file_path("/a/\0a").is_none());
Sourcepub fn from_directory_path<P: AsRef<Path>>(path: P) -> Option<Retained<Self>>
Available on crate feature std
and Unix and non-crate feature gnustep-1-7
only.
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Option<Retained<Self>>
std
and Unix and non-crate feature gnustep-1-7
only.Create a directory url from a Path
.
This differs from from_file_path
in that the
path is treated as a directory, which means that other normalization
rules are applied to it (to make it end with a /
).
§Examples
use std::path::Path;
use objc2_foundation::NSURL;
// Directory paths get trailing slashes appended
let url = NSURL::from_directory_path("/Library").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/"));
// Unless they already have them.
let url = NSURL::from_directory_path("/Library/").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/"));
// Similarly for relative paths.
let url = NSURL::from_directory_path("foo").unwrap();
assert_eq!(url.to_file_path().unwrap(), std::env::current_dir().unwrap().join("foo/"));
// Various dots may be stripped.
let url = NSURL::from_directory_path("/Library/././.").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/"));
// Though of course not if they have semantic meaning.
let url = NSURL::from_directory_path("/Library/..").unwrap();
assert_eq!(url.to_file_path().unwrap(), Path::new("/Library/.."));
Sourcepub fn to_file_path(&self) -> Option<PathBuf>
Available on crate feature std
and Unix and non-crate feature gnustep-1-7
only.
pub fn to_file_path(&self) -> Option<PathBuf>
std
and Unix and non-crate feature gnustep-1-7
only.Extract the path part of the URL as a PathBuf
.
This will return a path regardless of isFileURL
.
It is the responsibility of the caller to ensure that the URL is valid
to use as a file URL.
§Compatibility note
This currently does not work for non-unicode paths (which are fairly rare on macOS since HFS+ was been superseded by APFS).
This also currently always returns absolute paths (it converts relative URL paths to absolute), but that may change in the future.
§Examples
use std::path::Path;
use objc2_foundation::{NSURL, NSString};
let url = unsafe { NSURL::URLWithString(&NSString::from_str("file:///tmp/foo.txt")).unwrap() };
assert_eq!(url.to_file_path().unwrap(), Path::new("/tmp/foo.txt"));
See also the examples in from_file_path
.
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 ClassType for NSURL
impl ClassType for NSURL
Source§const NAME: &'static str = "NSURL"
const NAME: &'static str = "NSURL"
Source§type ThreadKind = <<NSURL as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSURL as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for NSURL
Available on crate feature NSObject
only.
impl CopyingHelper for NSURL
NSObject
only.Source§impl DefaultRetained for NSURL
impl DefaultRetained for NSURL
Source§impl NSCoding for NSURL
impl NSCoding for NSURL
Source§unsafe fn encodeWithCoder(&self, coder: &NSCoder)
unsafe fn encodeWithCoder(&self, coder: &NSCoder)
NSObject
and NSCoder
only.Source§impl NSCopying for NSURL
impl NSCopying for NSURL
Source§impl NSItemProviderReading for NSURL
impl NSItemProviderReading for NSURL
Source§impl NSItemProviderWriting for NSURL
impl NSItemProviderWriting for NSURL
Source§fn writableTypeIdentifiersForItemProvider_class() -> Retained<NSArray<NSString>>
fn writableTypeIdentifiersForItemProvider_class() -> Retained<NSArray<NSString>>
NSArray
and NSString
and NSItemProvider
only.Source§fn writableTypeIdentifiersForItemProvider(&self) -> Retained<NSArray<NSString>>
fn writableTypeIdentifiersForItemProvider(&self) -> Retained<NSArray<NSString>>
NSArray
and NSString
and NSItemProvider
only.Source§fn itemProviderVisibilityForRepresentationWithTypeIdentifier_class(
type_identifier: &NSString,
) -> NSItemProviderRepresentationVisibility
fn itemProviderVisibilityForRepresentationWithTypeIdentifier_class( type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
NSItemProvider
and NSString
only.Source§fn itemProviderVisibilityForRepresentationWithTypeIdentifier(
&self,
type_identifier: &NSString,
) -> NSItemProviderRepresentationVisibility
fn itemProviderVisibilityForRepresentationWithTypeIdentifier( &self, type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
NSItemProvider
and NSString
only.Source§unsafe fn loadDataWithTypeIdentifier_forItemProviderCompletionHandler(
&self,
type_identifier: &NSString,
completion_handler: &DynBlock<dyn Fn(*mut NSData, *mut NSError)>,
) -> Option<Retained<NSProgress>>
unsafe fn loadDataWithTypeIdentifier_forItemProviderCompletionHandler( &self, type_identifier: &NSString, completion_handler: &DynBlock<dyn Fn(*mut NSData, *mut NSError)>, ) -> Option<Retained<NSProgress>>
NSData
and NSError
and NSProgress
and NSString
and block2
and NSItemProvider
only.Source§impl NSObjectProtocol for NSURL
impl NSObjectProtocol for NSURL
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