#[repr(C)]pub struct NSURL { /* private fields */ }NSURL only.Expand description
Implementations§
Source§impl NSURL
impl NSURL
pub unsafe fn initWithScheme_host_path( this: Allocated<Self>, scheme: &NSString, host: Option<&NSString>, path: &NSString, ) -> Option<Retained<Self>>
NSString only.pub unsafe fn initFileURLWithPath_isDirectory_relativeToURL( this: Allocated<Self>, path: &NSString, is_dir: bool, base_url: Option<&NSURL>, ) -> Retained<Self>
NSString only.pub unsafe fn initFileURLWithPath_relativeToURL( this: Allocated<Self>, path: &NSString, base_url: Option<&NSURL>, ) -> Retained<Self>
NSString only.pub unsafe fn initFileURLWithPath_isDirectory( this: Allocated<Self>, path: &NSString, is_dir: bool, ) -> Retained<Self>
NSString only.pub unsafe fn initFileURLWithPath( this: Allocated<Self>, path: &NSString, ) -> Retained<Self>
NSString only.pub unsafe fn fileURLWithPath_isDirectory_relativeToURL( path: &NSString, is_dir: bool, base_url: Option<&NSURL>, ) -> Retained<NSURL>
NSString only.pub unsafe fn fileURLWithPath_relativeToURL( path: &NSString, base_url: Option<&NSURL>, ) -> Retained<NSURL>
NSString only.pub unsafe fn fileURLWithPath_isDirectory( path: &NSString, is_dir: bool, ) -> Retained<NSURL>
NSString only.pub unsafe fn fileURLWithPath(path: &NSString) -> Retained<NSURL>
NSString only.pub unsafe fn initFileURLWithFileSystemRepresentation_isDirectory_relativeToURL( this: Allocated<Self>, path: NonNull<c_char>, is_dir: bool, base_url: Option<&NSURL>, ) -> Retained<Self>
pub unsafe fn fileURLWithFileSystemRepresentation_isDirectory_relativeToURL( path: NonNull<c_char>, is_dir: bool, base_url: Option<&NSURL>, ) -> Retained<NSURL>
pub unsafe fn initWithString( this: Allocated<Self>, url_string: &NSString, ) -> Option<Retained<Self>>
NSString only.pub unsafe fn initWithString_relativeToURL( this: Allocated<Self>, url_string: &NSString, base_url: Option<&NSURL>, ) -> Option<Retained<Self>>
NSString only.pub unsafe fn URLWithString(url_string: &NSString) -> Option<Retained<Self>>
NSString only.pub unsafe fn URLWithString_relativeToURL( url_string: &NSString, base_url: Option<&NSURL>, ) -> Option<Retained<Self>>
NSString only.Sourcepub unsafe fn initWithString_encodingInvalidCharacters(
this: Allocated<Self>,
url_string: &NSString,
encoding_invalid_characters: bool,
) -> Option<Retained<Self>>
Available on crate feature NSString only.
pub unsafe 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
NSURLshould try to encode an invalid URL string, false otherwise. - Returns: An
NSURLinstance for a valid URL, ornilif the URL is invalid.
Sourcepub unsafe fn URLWithString_encodingInvalidCharacters(
url_string: &NSString,
encoding_invalid_characters: bool,
) -> Option<Retained<Self>>
Available on crate feature NSString only.
pub unsafe 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
NSURLshould try to encode an invalid URL string, false otherwise. - Returns: An
NSURLinstance for a valid URL, ornilif the URL is invalid.
pub unsafe fn initWithDataRepresentation_relativeToURL( this: Allocated<Self>, data: &NSData, base_url: Option<&NSURL>, ) -> Retained<Self>
NSData only.pub unsafe fn URLWithDataRepresentation_relativeToURL( data: &NSData, base_url: Option<&NSURL>, ) -> Retained<NSURL>
NSData only.pub unsafe fn initAbsoluteURLWithDataRepresentation_relativeToURL( this: Allocated<Self>, data: &NSData, base_url: Option<&NSURL>, ) -> Retained<Self>
NSData only.pub unsafe fn absoluteURLWithDataRepresentation_relativeToURL( data: &NSData, base_url: Option<&NSURL>, ) -> Retained<NSURL>
NSData only.pub unsafe fn dataRepresentation(&self) -> Retained<NSData>
NSData only.pub unsafe fn absoluteString(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn relativeString(&self) -> Retained<NSString>
NSString only.pub unsafe fn baseURL(&self) -> Option<Retained<NSURL>>
pub unsafe fn absoluteURL(&self) -> Option<Retained<NSURL>>
pub unsafe fn scheme(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn resourceSpecifier(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn host(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn port(&self) -> Option<Retained<NSNumber>>
NSValue only.pub unsafe fn user(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn password(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn path(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn fragment(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn parameterString(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn query(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn relativePath(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn hasDirectoryPath(&self) -> bool
pub unsafe fn getFileSystemRepresentation_maxLength( &self, buffer: NonNull<c_char>, max_buffer_length: NSUInteger, ) -> bool
pub unsafe fn fileSystemRepresentation(&self) -> NonNull<c_char>
pub unsafe fn isFileURL(&self) -> bool
pub unsafe fn standardizedURL(&self) -> Option<Retained<NSURL>>
pub unsafe fn isFileReferenceURL(&self) -> bool
pub unsafe fn fileReferenceURL(&self) -> Option<Retained<NSURL>>
pub unsafe fn filePathURL(&self) -> Option<Retained<NSURL>>
pub unsafe fn getResourceValue_forKey_error( &self, value: &mut Option<Retained<AnyObject>>, key: &NSURLResourceKey, ) -> Result<(), Retained<NSError>>
NSError and NSString only.pub unsafe fn resourceValuesForKeys_error( &self, keys: &NSArray<NSURLResourceKey>, ) -> Result<Retained<NSDictionary<NSURLResourceKey, AnyObject>>, Retained<NSError>>
NSArray and NSDictionary and NSError and NSString only.pub unsafe fn setResourceValue_forKey_error( &self, value: Option<&AnyObject>, key: &NSURLResourceKey, ) -> Result<(), Retained<NSError>>
NSError and NSString only.pub unsafe fn setResourceValues_error( &self, keyed_values: &NSDictionary<NSURLResourceKey, AnyObject>, ) -> Result<(), Retained<NSError>>
NSDictionary and NSError and NSString only.pub unsafe fn removeCachedResourceValueForKey(&self, key: &NSURLResourceKey)
NSString only.pub unsafe fn removeAllCachedResourceValues(&self)
pub unsafe fn setTemporaryResourceValue_forKey( &self, value: Option<&AnyObject>, key: &NSURLResourceKey, )
NSString only.pub unsafe 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.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.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.pub unsafe fn resourceValuesForKeys_fromBookmarkData( keys: &NSArray<NSURLResourceKey>, bookmark_data: &NSData, ) -> Option<Retained<NSDictionary<NSURLResourceKey, AnyObject>>>
NSArray and NSData and NSDictionary and NSString only.pub unsafe fn writeBookmarkData_toURL_options_error( bookmark_data: &NSData, bookmark_file_url: &NSURL, options: NSURLBookmarkFileCreationOptions, ) -> Result<(), Retained<NSError>>
NSData and NSError only.pub unsafe fn bookmarkDataWithContentsOfURL_error( bookmark_file_url: &NSURL, ) -> Result<Retained<NSData>, Retained<NSError>>
NSData and NSError only.pub unsafe 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.
pub unsafe fn getPromisedItemResourceValue_forKey_error( &self, value: &mut Option<Retained<AnyObject>>, key: &NSURLResourceKey, ) -> Result<(), Retained<NSError>>
NSError and NSString only.pub unsafe fn promisedItemResourceValuesForKeys_error( &self, keys: &NSArray<NSURLResourceKey>, ) -> Result<Retained<NSDictionary<NSURLResourceKey, AnyObject>>, Retained<NSError>>
NSArray and NSDictionary and NSError and NSString only.pub unsafe fn checkPromisedItemIsReachableAndReturnError( &self, ) -> Result<(), Retained<NSError>>
NSError only.impl NSURL
NSItemProvider.
Source§impl NSURL
NSURLPathUtilities.
impl NSURL
NSURLPathUtilities.
pub unsafe fn fileURLWithPathComponents( components: &NSArray<NSString>, ) -> Option<Retained<NSURL>>
NSArray and NSString only.pub unsafe fn pathComponents(&self) -> Option<Retained<NSArray<NSString>>>
NSArray and NSString only.pub unsafe fn lastPathComponent(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn pathExtension(&self) -> Option<Retained<NSString>>
NSString only.pub unsafe fn URLByAppendingPathComponent( &self, path_component: &NSString, ) -> Option<Retained<NSURL>>
NSString only.pub unsafe fn URLByAppendingPathComponent_isDirectory( &self, path_component: &NSString, is_directory: bool, ) -> Option<Retained<NSURL>>
NSString only.pub unsafe fn URLByDeletingLastPathComponent(&self) -> Option<Retained<NSURL>>
pub unsafe fn URLByAppendingPathExtension( &self, path_extension: &NSString, ) -> Option<Retained<NSURL>>
NSString only.pub unsafe fn URLByDeletingPathExtension(&self) -> Option<Retained<NSURL>>
pub unsafe fn checkResourceIsReachableAndReturnError( &self, ) -> Result<(), Retained<NSError>>
NSError only.pub unsafe fn URLByStandardizingPath(&self) -> Option<Retained<NSURL>>
pub unsafe fn URLByResolvingSymlinksInPath(&self) -> Option<Retained<NSURL>>
Source§impl NSURL
NSURLLoading.
impl NSURL
NSURLLoading.
pub unsafe fn resourceDataUsingCache( &self, should_use_cache: bool, ) -> Option<Retained<NSData>>
NSData only.pub unsafe fn loadResourceDataNotifyingClient_usingCache( &self, client: &AnyObject, should_use_cache: bool, )
pub unsafe fn propertyForKey( &self, property_key: &NSString, ) -> Option<Retained<AnyObject>>
NSString only.pub unsafe fn setResourceData(&self, data: &NSData) -> bool
NSData only.pub unsafe fn setProperty_forKey( &self, property: &AnyObject, property_key: &NSString, ) -> bool
NSString only.pub unsafe fn URLHandleUsingCache( &self, should_use_cache: bool, ) -> Option<Retained<NSURLHandle>>
NSURLHandle 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.
§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 NSCopying for NSURL
Available on crate feature NSObject only.
impl NSCopying for NSURL
NSObject only.Source§impl NSItemProviderReading for NSURL
Available on crate feature NSItemProvider only.
impl NSItemProviderReading for NSURL
NSItemProvider only.Source§impl NSItemProviderWriting for NSURL
Available on crate feature NSItemProvider only.
impl NSItemProviderWriting for NSURL
NSItemProvider only.Source§unsafe fn writableTypeIdentifiersForItemProvider_class() -> Retained<NSArray<NSString>>
unsafe fn writableTypeIdentifiersForItemProvider_class() -> Retained<NSArray<NSString>>
NSArray and NSString only.Source§unsafe fn writableTypeIdentifiersForItemProvider(
&self,
) -> Retained<NSArray<NSString>>
unsafe fn writableTypeIdentifiersForItemProvider( &self, ) -> Retained<NSArray<NSString>>
NSArray and NSString only.Source§unsafe fn itemProviderVisibilityForRepresentationWithTypeIdentifier_class(
type_identifier: &NSString,
) -> NSItemProviderRepresentationVisibility
unsafe fn itemProviderVisibilityForRepresentationWithTypeIdentifier_class( type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
NSString only.Source§unsafe fn itemProviderVisibilityForRepresentationWithTypeIdentifier(
&self,
type_identifier: &NSString,
) -> NSItemProviderRepresentationVisibility
unsafe fn itemProviderVisibilityForRepresentationWithTypeIdentifier( &self, type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
NSString only.Source§unsafe fn loadDataWithTypeIdentifier_forItemProviderCompletionHandler(
&self,
type_identifier: &NSString,
completion_handler: &Block<dyn Fn(*mut NSData, *mut NSError)>,
) -> Option<Retained<NSProgress>>
unsafe fn loadDataWithTypeIdentifier_forItemProviderCompletionHandler( &self, type_identifier: &NSString, completion_handler: &Block<dyn Fn(*mut NSData, *mut NSError)>, ) -> Option<Retained<NSProgress>>
NSData and NSError and NSProgress and NSString and block2 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_refSource§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
Source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
Source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
Source§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
Source§impl NSSecureCoding for NSURL
Available on crate feature NSObject only.
impl NSSecureCoding for NSURL
NSObject only.