#[repr(C)]pub struct ScreenSaverDefaults { /* private fields */ }ScreenSaverDefaults only.Expand description
A class that defines a set of methods for saving and restoring user defaults for screen savers.
ScreenSaverDefaults gives you access to preference values you need to
configure your screen saver. Because multiple apps can load a screen saver,
you can’t use the standard
<doc
://com.apple.documentation/documentation/foundation/nsuserdefaults>
object to store preferences. Instead, instantiate this class using the
ScreenSaverDefaults/defaultsForModuleWithName: method, which takes your
screen saver’s bundle identifier as a parameter. The resulting object gives
you a way to store your preference values and associate them only with your
screen saver. Use the inherited
<doc
://com.apple.documentation/documentation/foundation/nsuserdefaults>
methods to load, store, or modify values.
See also Apple’s documentation
Implementations§
Source§impl ScreenSaverDefaults
impl ScreenSaverDefaults
Sourcepub unsafe fn defaultsForModuleWithName(
in_module_name: &NSString,
) -> Option<Retained<Self>>
pub unsafe fn defaultsForModuleWithName( in_module_name: &NSString, ) -> Option<Retained<Self>>
Returns a screen saver defaults instance that reads and writes defaults for the specified module.
- Parameters:
- inModuleName: The bundle identifier for the module.
Source§impl ScreenSaverDefaults
Methods declared on superclass NSUserDefaults.
impl ScreenSaverDefaults
Methods declared on superclass NSUserDefaults.
Sourcepub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
-init is equivalent to -initWithSuiteName:nil
Sourcepub unsafe fn initWithSuiteName(
this: Allocated<Self>,
suitename: Option<&NSString>,
) -> Option<Retained<Self>>
pub unsafe fn initWithSuiteName( this: Allocated<Self>, suitename: Option<&NSString>, ) -> Option<Retained<Self>>
-initWithSuiteName: initializes an instance of NSUserDefaults that searches the shared preferences search list for the domain ‘suitename’. For example, using the identifier of an application group will cause the receiver to search the preferences for that group. Passing the current application’s bundle identifier, NSGlobalDomain, or the corresponding CFPreferences constants is an error. Passing nil will search the default search list.
Methods from Deref<Target = NSUserDefaults>§
Sourcepub unsafe fn objectForKey(
&self,
default_name: &NSString,
) -> Option<Retained<AnyObject>>
Available on crate feature NSString only.
pub unsafe fn objectForKey( &self, default_name: &NSString, ) -> Option<Retained<AnyObject>>
NSString only.-objectForKey: will search the receiver’s search list for a default with the key ‘defaultName’ and return it. If another process has changed defaults in the search list, NSUserDefaults will automatically update to the latest values. If the key in question has been marked as ubiquitous via a Defaults Configuration File, the latest value may not be immediately available, and the registered value will be returned instead.
Sourcepub unsafe fn setObject_forKey(
&self,
value: Option<&AnyObject>,
default_name: &NSString,
)
Available on crate feature NSString only.
pub unsafe fn setObject_forKey( &self, value: Option<&AnyObject>, default_name: &NSString, )
NSString only.-setObject:forKey: immediately stores a value (or removes the value if nil is passed as the value) for the provided key in the search list entry for the receiver’s suite name in the current user and any host, then asynchronously stores the value persistently, where it is made available to other processes.
Sourcepub unsafe fn removeObjectForKey(&self, default_name: &NSString)
Available on crate feature NSString only.
pub unsafe fn removeObjectForKey(&self, default_name: &NSString)
NSString only.-removeObjectForKey: is equivalent to -[… setObject:nil forKey:defaultName]
Sourcepub unsafe fn stringForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSString>>
Available on crate feature NSString only.
pub unsafe fn stringForKey( &self, default_name: &NSString, ) -> Option<Retained<NSString>>
NSString only.-stringForKey: is equivalent to -objectForKey:, except that it will convert NSNumber values to their NSString representation. If a non-string non-number value is found, nil will be returned.
Sourcepub unsafe fn arrayForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSArray>>
Available on crate features NSArray and NSString only.
pub unsafe fn arrayForKey( &self, default_name: &NSString, ) -> Option<Retained<NSArray>>
NSArray and NSString only.-arrayForKey: is equivalent to -objectForKey:, except that it will return nil if the value is not an NSArray.
Sourcepub unsafe fn dictionaryForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSDictionary<NSString>>>
Available on crate features NSDictionary and NSString only.
pub unsafe fn dictionaryForKey( &self, default_name: &NSString, ) -> Option<Retained<NSDictionary<NSString>>>
NSDictionary and NSString only.-dictionaryForKey: is equivalent to -objectForKey:, except that it will return nil if the value is not an NSDictionary.
Sourcepub unsafe fn dataForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSData>>
Available on crate features NSData and NSString only.
pub unsafe fn dataForKey( &self, default_name: &NSString, ) -> Option<Retained<NSData>>
NSData and NSString only.-dataForKey: is equivalent to -objectForKey:, except that it will return nil if the value is not an NSData.
Sourcepub unsafe fn stringArrayForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSArray<NSString>>>
Available on crate features NSArray and NSString only.
pub unsafe fn stringArrayForKey( &self, default_name: &NSString, ) -> Option<Retained<NSArray<NSString>>>
NSArray and NSString only.-stringForKey: is equivalent to -objectForKey:, except that it will return nil if the value is not an NSArray <NSString *>. Note that unlike -stringForKey:, NSNumbers are not converted to NSStrings.
Sourcepub unsafe fn integerForKey(&self, default_name: &NSString) -> isize
Available on crate feature NSString only.
pub unsafe fn integerForKey(&self, default_name: &NSString) -> isize
NSString only.-integerForKey: is equivalent to -objectForKey:, except that it converts the returned value to an NSInteger. If the value is an NSNumber, the result of -integerValue will be returned. If the value is an NSString, it will be converted to NSInteger if possible. If the value is a boolean, it will be converted to either 1 for YES or 0 for NO. If the value is absent or can’t be converted to an integer, 0 will be returned.
Sourcepub unsafe fn floatForKey(&self, default_name: &NSString) -> f32
Available on crate feature NSString only.
pub unsafe fn floatForKey(&self, default_name: &NSString) -> f32
NSString only.-floatForKey: is similar to -integerForKey:, except that it returns a float, and boolean values will not be converted.
Sourcepub unsafe fn doubleForKey(&self, default_name: &NSString) -> f64
Available on crate feature NSString only.
pub unsafe fn doubleForKey(&self, default_name: &NSString) -> f64
NSString only.-doubleForKey: is similar to -integerForKey:, except that it returns a double, and boolean values will not be converted.
Sourcepub unsafe fn boolForKey(&self, default_name: &NSString) -> bool
Available on crate feature NSString only.
pub unsafe fn boolForKey(&self, default_name: &NSString) -> bool
NSString only.-boolForKey: is equivalent to -objectForKey:, except that it converts the returned value to a BOOL. If the value is an NSNumber, NO will be returned if the value is 0, YES otherwise. If the value is an NSString, values of “YES” or “1” will return YES, and values of “NO”, “0”, or any other string will return NO. If the value is absent or can’t be converted to a BOOL, NO will be returned.
Sourcepub unsafe fn URLForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSURL>>
Available on crate features NSString and NSURL only.
pub unsafe fn URLForKey( &self, default_name: &NSString, ) -> Option<Retained<NSURL>>
NSString and NSURL only.-URLForKey: is equivalent to -objectForKey: except that it converts the returned value to an NSURL. If the value is an NSString path, then it will construct a file URL to that path. If the value is an archived URL from -setURL:forKey: it will be unarchived. If the value is absent or can’t be converted to an NSURL, nil will be returned.
Sourcepub unsafe fn setInteger_forKey(&self, value: isize, default_name: &NSString)
Available on crate feature NSString only.
pub unsafe fn setInteger_forKey(&self, value: isize, default_name: &NSString)
NSString only.-setInteger:forKey: is equivalent to -setObject:forKey: except that the value is converted from an NSInteger to an NSNumber.
Sourcepub unsafe fn setFloat_forKey(&self, value: f32, default_name: &NSString)
Available on crate feature NSString only.
pub unsafe fn setFloat_forKey(&self, value: f32, default_name: &NSString)
NSString only.-setFloat:forKey: is equivalent to -setObject:forKey: except that the value is converted from a float to an NSNumber.
Sourcepub unsafe fn setDouble_forKey(&self, value: f64, default_name: &NSString)
Available on crate feature NSString only.
pub unsafe fn setDouble_forKey(&self, value: f64, default_name: &NSString)
NSString only.-setDouble:forKey: is equivalent to -setObject:forKey: except that the value is converted from a double to an NSNumber.
Sourcepub unsafe fn setBool_forKey(&self, value: bool, default_name: &NSString)
Available on crate feature NSString only.
pub unsafe fn setBool_forKey(&self, value: bool, default_name: &NSString)
NSString only.-setBool:forKey: is equivalent to -setObject:forKey: except that the value is converted from a BOOL to an NSNumber.
Sourcepub unsafe fn setURL_forKey(&self, url: Option<&NSURL>, default_name: &NSString)
Available on crate features NSString and NSURL only.
pub unsafe fn setURL_forKey(&self, url: Option<&NSURL>, default_name: &NSString)
NSString and NSURL only.-setURL:forKey is equivalent to -setObject:forKey: except that the value is archived to an NSData. Use -URLForKey: to retrieve values set this way.
Sourcepub unsafe fn registerDefaults(
&self,
registration_dictionary: &NSDictionary<NSString>,
)
Available on crate features NSDictionary and NSString only.
pub unsafe fn registerDefaults( &self, registration_dictionary: &NSDictionary<NSString>, )
NSDictionary and NSString only.-registerDefaults: adds the registrationDictionary to the last item in every search list. This means that after NSUserDefaults has looked for a value in every other valid location, it will look in registered defaults, making them useful as a “fallback” value. Registered defaults are never stored between runs of an application, and are visible only to the application that registers them.
Default values from Defaults Configuration Files will automatically be registered.
Sourcepub unsafe fn addSuiteNamed(&self, suite_name: &NSString)
Available on crate feature NSString only.
pub unsafe fn addSuiteNamed(&self, suite_name: &NSString)
NSString only.-addSuiteNamed: adds the full search list for ‘suiteName’ as a sub-search-list of the receiver’s. The additional search lists are searched after the current domain, but before global defaults. Passing NSGlobalDomain or the current application’s bundle identifier is unsupported.
Sourcepub unsafe fn removeSuiteNamed(&self, suite_name: &NSString)
Available on crate feature NSString only.
pub unsafe fn removeSuiteNamed(&self, suite_name: &NSString)
NSString only.-removeSuiteNamed: removes a sub-searchlist added via -addSuiteNamed:.
Sourcepub unsafe fn dictionaryRepresentation(
&self,
) -> Retained<NSDictionary<NSString>>
Available on crate features NSDictionary and NSString only.
pub unsafe fn dictionaryRepresentation( &self, ) -> Retained<NSDictionary<NSString>>
NSDictionary and NSString only.-dictionaryRepresentation returns a composite snapshot of the values in the receiver’s search list, such that [[receiver dictionaryRepresentation] objectForKey:x] will return the same thing as [receiver objectForKey:x].
pub unsafe fn volatileDomainNames(&self) -> Retained<NSArray<NSString>>
NSArray and NSString only.pub unsafe fn volatileDomainForName( &self, domain_name: &NSString, ) -> Retained<NSDictionary<NSString>>
NSDictionary and NSString only.pub unsafe fn setVolatileDomain_forName( &self, domain: &NSDictionary<NSString>, domain_name: &NSString, )
NSDictionary and NSString only.pub unsafe fn removeVolatileDomainForName(&self, domain_name: &NSString)
NSString only.Sourcepub unsafe fn persistentDomainNames(&self) -> Retained<NSArray>
👎Deprecated: Not recommendedAvailable on crate feature NSArray only.
pub unsafe fn persistentDomainNames(&self) -> Retained<NSArray>
NSArray only.-persistentDomainNames returns an incomplete list of domains that have preferences stored in them.
Sourcepub unsafe fn persistentDomainForName(
&self,
domain_name: &NSString,
) -> Option<Retained<NSDictionary<NSString>>>
Available on crate features NSDictionary and NSString only.
pub unsafe fn persistentDomainForName( &self, domain_name: &NSString, ) -> Option<Retained<NSDictionary<NSString>>>
NSDictionary and NSString only.-persistentDomainForName: returns a dictionary representation of the search list entry specified by ‘domainName’, the current user, and any host.
Sourcepub unsafe fn setPersistentDomain_forName(
&self,
domain: &NSDictionary<NSString>,
domain_name: &NSString,
)
Available on crate features NSDictionary and NSString only.
pub unsafe fn setPersistentDomain_forName( &self, domain: &NSDictionary<NSString>, domain_name: &NSString, )
NSDictionary and NSString only.-setPersistentDomain:forName: replaces all values in the search list entry specified by ‘domainName’, the current user, and any host, with the values in ‘domain’. The change will be persisted.
Sourcepub unsafe fn removePersistentDomainForName(&self, domain_name: &NSString)
Available on crate feature NSString only.
pub unsafe fn removePersistentDomainForName(&self, domain_name: &NSString)
NSString only.-removePersistentDomainForName: removes all values from the search list entry specified by ‘domainName’, the current user, and any host. The change is persistent.
Sourcepub unsafe fn synchronize(&self) -> bool
pub unsafe fn synchronize(&self) -> bool
-synchronize is deprecated and will be marked with the API_DEPRECATED macro in a future release.
-synchronize blocks the calling thread until all in-progress set operations have completed. This is no longer necessary. Replacements for previous uses of -synchronize depend on what the intent of calling synchronize was. If you synchronized…
- …before reading in order to fetch updated values: remove the synchronize call
- …after writing in order to notify another program to read: the other program can use KVO to observe the default without needing to notify
- …before exiting in a non-app (command line tool, agent, or daemon) process: call CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication)
- …for any other reason: remove the synchronize call
pub unsafe fn objectIsForcedForKey(&self, key: &NSString) -> bool
NSString only.pub unsafe fn objectIsForcedForKey_inDomain( &self, key: &NSString, domain: &NSString, ) -> bool
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.
§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 ScreenSaverDefaults
impl AsRef<AnyObject> for ScreenSaverDefaults
Source§impl AsRef<NSObject> for ScreenSaverDefaults
impl AsRef<NSObject> for ScreenSaverDefaults
Source§impl AsRef<NSUserDefaults> for ScreenSaverDefaults
impl AsRef<NSUserDefaults> for ScreenSaverDefaults
Source§fn as_ref(&self) -> &NSUserDefaults
fn as_ref(&self) -> &NSUserDefaults
Source§impl Borrow<AnyObject> for ScreenSaverDefaults
impl Borrow<AnyObject> for ScreenSaverDefaults
Source§impl Borrow<NSObject> for ScreenSaverDefaults
impl Borrow<NSObject> for ScreenSaverDefaults
Source§impl Borrow<NSUserDefaults> for ScreenSaverDefaults
impl Borrow<NSUserDefaults> for ScreenSaverDefaults
Source§fn borrow(&self) -> &NSUserDefaults
fn borrow(&self) -> &NSUserDefaults
Source§impl ClassType for ScreenSaverDefaults
impl ClassType for ScreenSaverDefaults
Source§const NAME: &'static str = "ScreenSaverDefaults"
const NAME: &'static str = "ScreenSaverDefaults"
Source§type Super = NSUserDefaults
type Super = NSUserDefaults
Source§type ThreadKind = <<ScreenSaverDefaults as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<ScreenSaverDefaults as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for ScreenSaverDefaults
impl Debug for ScreenSaverDefaults
Source§impl Deref for ScreenSaverDefaults
impl Deref for ScreenSaverDefaults
Source§impl Hash for ScreenSaverDefaults
impl Hash for ScreenSaverDefaults
Source§impl Message for ScreenSaverDefaults
impl Message for ScreenSaverDefaults
Source§impl NSObjectProtocol for ScreenSaverDefaults
impl NSObjectProtocol for ScreenSaverDefaults
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