pub struct NSBundle { /* private fields */ }NSBundle only.Expand description
Implementations§
Source§impl NSBundle
impl NSBundle
pub fn mainBundle() -> Retained<NSBundle>
pub fn bundleWithPath(path: &NSString) -> Option<Retained<Self>>
NSString only.pub fn initWithPath( this: Allocated<Self>, path: &NSString, ) -> Option<Retained<Self>>
NSString only.pub fn bundleWithURL(url: &NSURL) -> Option<Retained<Self>>
NSURL only.pub fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Option<Retained<Self>>
NSURL only.Sourcepub unsafe fn bundleForClass(a_class: &AnyClass) -> Retained<NSBundle>
pub unsafe fn bundleForClass(a_class: &AnyClass) -> Retained<NSBundle>
§Safety
a_class probably has further requirements.
pub fn bundleWithIdentifier(identifier: &NSString) -> Option<Retained<NSBundle>>
NSString only.pub unsafe fn allBundles() -> Retained<NSArray<NSBundle>>
NSArray only.pub unsafe fn allFrameworks() -> Retained<NSArray<NSBundle>>
NSArray only.pub unsafe fn load(&self) -> bool
pub fn isLoaded(&self) -> bool
pub unsafe fn unload(&self) -> bool
pub fn preflightAndReturnError(&self) -> Result<(), Retained<NSError>>
NSError only.pub unsafe fn loadAndReturnError(&self) -> Result<(), Retained<NSError>>
NSError only.pub fn bundleURL(&self) -> Retained<NSURL>
NSURL only.pub fn resourceURL(&self) -> Option<Retained<NSURL>>
NSURL only.pub fn executableURL(&self) -> Option<Retained<NSURL>>
NSURL only.pub fn URLForAuxiliaryExecutable( &self, executable_name: &NSString, ) -> Option<Retained<NSURL>>
NSString and NSURL only.pub fn privateFrameworksURL(&self) -> Option<Retained<NSURL>>
NSURL only.NSURL only.NSURL only.pub fn builtInPlugInsURL(&self) -> Option<Retained<NSURL>>
NSURL only.pub fn appStoreReceiptURL(&self) -> Option<Retained<NSURL>>
NSURL only.pub fn bundlePath(&self) -> Retained<NSString>
NSString only.pub fn resourcePath(&self) -> Option<Retained<NSString>>
NSString only.pub fn executablePath(&self) -> Option<Retained<NSString>>
NSString only.pub fn pathForAuxiliaryExecutable( &self, executable_name: &NSString, ) -> Option<Retained<NSString>>
NSString only.pub fn privateFrameworksPath(&self) -> Option<Retained<NSString>>
NSString only.NSString only.NSString only.pub fn builtInPlugInsPath(&self) -> Option<Retained<NSString>>
NSString only.pub fn URLForResource_withExtension_subdirectory_inBundleWithURL( name: Option<&NSString>, ext: Option<&NSString>, subpath: Option<&NSString>, bundle_url: &NSURL, ) -> Option<Retained<NSURL>>
NSString and NSURL only.pub fn URLsForResourcesWithExtension_subdirectory_inBundleWithURL( ext: Option<&NSString>, subpath: Option<&NSString>, bundle_url: &NSURL, ) -> Option<Retained<NSArray<NSURL>>>
NSArray and NSString and NSURL only.pub fn URLForResource_withExtension( &self, name: Option<&NSString>, ext: Option<&NSString>, ) -> Option<Retained<NSURL>>
NSString and NSURL only.pub fn URLForResource_withExtension_subdirectory( &self, name: Option<&NSString>, ext: Option<&NSString>, subpath: Option<&NSString>, ) -> Option<Retained<NSURL>>
NSString and NSURL only.pub fn URLForResource_withExtension_subdirectory_localization( &self, name: Option<&NSString>, ext: Option<&NSString>, subpath: Option<&NSString>, localization_name: Option<&NSString>, ) -> Option<Retained<NSURL>>
NSString and NSURL only.pub fn URLsForResourcesWithExtension_subdirectory( &self, ext: Option<&NSString>, subpath: Option<&NSString>, ) -> Option<Retained<NSArray<NSURL>>>
NSArray and NSString and NSURL only.pub fn URLsForResourcesWithExtension_subdirectory_localization( &self, ext: Option<&NSString>, subpath: Option<&NSString>, localization_name: Option<&NSString>, ) -> Option<Retained<NSArray<NSURL>>>
NSArray and NSString and NSURL only.pub fn pathForResource_ofType_inDirectory_class( name: Option<&NSString>, ext: Option<&NSString>, bundle_path: &NSString, ) -> Option<Retained<NSString>>
NSString only.pub fn pathsForResourcesOfType_inDirectory_class( ext: Option<&NSString>, bundle_path: &NSString, ) -> Retained<NSArray<NSString>>
NSArray and NSString only.pub fn pathForResource_ofType( &self, name: Option<&NSString>, ext: Option<&NSString>, ) -> Option<Retained<NSString>>
NSString only.pub fn pathForResource_ofType_inDirectory( &self, name: Option<&NSString>, ext: Option<&NSString>, subpath: Option<&NSString>, ) -> Option<Retained<NSString>>
NSString only.pub fn pathForResource_ofType_inDirectory_forLocalization( &self, name: Option<&NSString>, ext: Option<&NSString>, subpath: Option<&NSString>, localization_name: Option<&NSString>, ) -> Option<Retained<NSString>>
NSString only.pub fn pathsForResourcesOfType_inDirectory( &self, ext: Option<&NSString>, subpath: Option<&NSString>, ) -> Retained<NSArray<NSString>>
NSArray and NSString only.pub fn pathsForResourcesOfType_inDirectory_forLocalization( &self, ext: Option<&NSString>, subpath: Option<&NSString>, localization_name: Option<&NSString>, ) -> Retained<NSArray<NSString>>
NSArray and NSString only.pub fn localizedStringForKey_value_table( &self, key: &NSString, value: Option<&NSString>, table_name: Option<&NSString>, ) -> Retained<NSString>
NSString only.Sourcepub fn localizedStringForKey_value_table_localizations(
&self,
key: &NSString,
value: Option<&NSString>,
table_name: Option<&NSString>,
localizations: &NSArray<NSString>,
) -> Retained<NSString>
Available on crate features NSArray and NSString only.
pub fn localizedStringForKey_value_table_localizations( &self, key: &NSString, value: Option<&NSString>, table_name: Option<&NSString>, localizations: &NSArray<NSString>, ) -> Retained<NSString>
NSArray and NSString only.Look up a localized string given a list of available localizations.
- Parameters:
- key: The key for the localized string to retrieve.
- value: A default value to return if a localized string for
keycannot be found. - tableName: The name of the strings file to search. If
nil, the method uses tables inLocalizable.strings. - localizations: An array of BCP 47 language codes corresponding to available localizations. Bundle compares the array against its available localizations, and uses the best result to retrieve the localized string. If empty, we treat it as no localization is available, and may return a fallback.
- Returns: A localized version of the string designated by
keyin tabletableName.
pub fn bundleIdentifier(&self) -> Option<Retained<NSString>>
NSString only.pub fn infoDictionary( &self, ) -> Option<Retained<NSDictionary<NSString, AnyObject>>>
NSDictionary and NSString only.pub fn localizedInfoDictionary( &self, ) -> Option<Retained<NSDictionary<NSString, AnyObject>>>
NSDictionary and NSString only.pub fn objectForInfoDictionaryKey( &self, key: &NSString, ) -> Option<Retained<AnyObject>>
NSString only.pub fn classNamed(&self, class_name: &NSString) -> Option<&'static AnyClass>
NSString only.pub fn principalClass(&self) -> Option<&'static AnyClass>
pub fn preferredLocalizations(&self) -> Retained<NSArray<NSString>>
NSArray and NSString only.pub fn localizations(&self) -> Retained<NSArray<NSString>>
NSArray and NSString only.pub fn developmentLocalization(&self) -> Option<Retained<NSString>>
NSString only.pub fn preferredLocalizationsFromArray( localizations_array: &NSArray<NSString>, ) -> Retained<NSArray<NSString>>
NSArray and NSString only.pub fn preferredLocalizationsFromArray_forPreferences( localizations_array: &NSArray<NSString>, preferences_array: Option<&NSArray<NSString>>, ) -> Retained<NSArray<NSString>>
NSArray and NSString only.pub fn executableArchitectures(&self) -> Option<Retained<NSArray<NSNumber>>>
NSArray and NSValue only.Source§impl NSBundle
NSBundleResourceRequestAdditions.
impl NSBundle
NSBundleResourceRequestAdditions.
pub fn setPreservationPriority_forTags( &self, priority: c_double, tags: &NSSet<NSString>, )
NSSet and NSString only.pub fn preservationPriorityForTag(&self, tag: &NSString) -> c_double
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 ClassType for NSBundle
impl ClassType for NSBundle
Source§const NAME: &'static str = "NSBundle"
const NAME: &'static str = "NSBundle"
Source§type ThreadKind = <<NSBundle as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSBundle as ClassType>::Super as ClassType>::ThreadKind
Source§impl DefaultRetained for NSBundle
impl DefaultRetained for NSBundle
Source§impl NSObjectProtocol for NSBundle
impl NSObjectProtocol for NSBundle
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