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 fn objectForKey(
&self,
default_name: &NSString,
) -> Option<Retained<AnyObject>>
pub fn objectForKey( &self, default_name: &NSString, ) -> Option<Retained<AnyObject>>
-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,
)
pub unsafe fn setObject_forKey( &self, value: Option<&AnyObject>, default_name: &NSString, )
-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.
§Safety
value should be of the correct type.
Sourcepub fn removeObjectForKey(&self, default_name: &NSString)
pub fn removeObjectForKey(&self, default_name: &NSString)
-removeObjectForKey: is equivalent to -[… setObject:nil forKey:defaultName]
Sourcepub fn stringForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSString>>
pub fn stringForKey( &self, default_name: &NSString, ) -> Option<Retained<NSString>>
-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 fn arrayForKey(&self, default_name: &NSString) -> Option<Retained<NSArray>>
pub fn arrayForKey(&self, default_name: &NSString) -> Option<Retained<NSArray>>
-arrayForKey: is equivalent to -objectForKey:, except that it will return nil if the value is not an NSArray.
Sourcepub fn dictionaryForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSDictionary<NSString>>>
pub fn dictionaryForKey( &self, default_name: &NSString, ) -> Option<Retained<NSDictionary<NSString>>>
-dictionaryForKey: is equivalent to -objectForKey:, except that it will return nil if the value is not an NSDictionary.
Sourcepub fn dataForKey(&self, default_name: &NSString) -> Option<Retained<NSData>>
pub fn dataForKey(&self, default_name: &NSString) -> Option<Retained<NSData>>
-dataForKey: is equivalent to -objectForKey:, except that it will return nil if the value is not an NSData.
Sourcepub fn stringArrayForKey(
&self,
default_name: &NSString,
) -> Option<Retained<NSArray<NSString>>>
pub fn stringArrayForKey( &self, default_name: &NSString, ) -> Option<Retained<NSArray<NSString>>>
-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 fn integerForKey(&self, default_name: &NSString) -> isize
pub fn integerForKey(&self, default_name: &NSString) -> isize
-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 fn floatForKey(&self, default_name: &NSString) -> f32
pub fn floatForKey(&self, default_name: &NSString) -> f32
-floatForKey: is similar to -integerForKey:, except that it returns a float, and boolean values will not be converted.
Sourcepub fn doubleForKey(&self, default_name: &NSString) -> f64
pub fn doubleForKey(&self, default_name: &NSString) -> f64
-doubleForKey: is similar to -integerForKey:, except that it returns a double, and boolean values will not be converted.
Sourcepub fn boolForKey(&self, default_name: &NSString) -> bool
pub fn boolForKey(&self, default_name: &NSString) -> bool
-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 fn URLForKey(&self, default_name: &NSString) -> Option<Retained<NSURL>>
pub fn URLForKey(&self, default_name: &NSString) -> Option<Retained<NSURL>>
-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 fn setInteger_forKey(&self, value: isize, default_name: &NSString)
pub fn setInteger_forKey(&self, value: isize, default_name: &NSString)
-setInteger:forKey: is equivalent to -setObject:forKey: except that the value is converted from an NSInteger to an NSNumber.
Sourcepub fn setFloat_forKey(&self, value: f32, default_name: &NSString)
pub fn setFloat_forKey(&self, value: f32, default_name: &NSString)
-setFloat:forKey: is equivalent to -setObject:forKey: except that the value is converted from a float to an NSNumber.
Sourcepub fn setDouble_forKey(&self, value: f64, default_name: &NSString)
pub fn setDouble_forKey(&self, value: f64, default_name: &NSString)
-setDouble:forKey: is equivalent to -setObject:forKey: except that the value is converted from a double to an NSNumber.
Sourcepub fn setBool_forKey(&self, value: bool, default_name: &NSString)
pub fn setBool_forKey(&self, value: bool, default_name: &NSString)
-setBool:forKey: is equivalent to -setObject:forKey: except that the value is converted from a BOOL to an NSNumber.
Sourcepub fn setURL_forKey(&self, url: Option<&NSURL>, default_name: &NSString)
pub fn setURL_forKey(&self, url: Option<&NSURL>, default_name: &NSString)
-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>,
)
pub unsafe fn registerDefaults( &self, registration_dictionary: &NSDictionary<NSString>, )
-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.
§Safety
registration_dictionary generic should be of the correct type.
Sourcepub fn addSuiteNamed(&self, suite_name: &NSString)
pub fn addSuiteNamed(&self, suite_name: &NSString)
-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 fn removeSuiteNamed(&self, suite_name: &NSString)
pub fn removeSuiteNamed(&self, suite_name: &NSString)
-removeSuiteNamed: removes a sub-searchlist added via -addSuiteNamed:.
Sourcepub fn dictionaryRepresentation(&self) -> Retained<NSDictionary<NSString>>
pub fn dictionaryRepresentation(&self) -> Retained<NSDictionary<NSString>>
-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 fn volatileDomainNames(&self) -> Retained<NSArray<NSString>>
pub fn volatileDomainForName( &self, domain_name: &NSString, ) -> Retained<NSDictionary<NSString>>
Sourcepub unsafe fn setVolatileDomain_forName(
&self,
domain: &NSDictionary<NSString>,
domain_name: &NSString,
)
pub unsafe fn setVolatileDomain_forName( &self, domain: &NSDictionary<NSString>, domain_name: &NSString, )
§Safety
domain generic should be of the correct type.
pub fn removeVolatileDomainForName(&self, domain_name: &NSString)
Sourcepub fn persistentDomainNames(&self) -> Retained<NSArray>
👎Deprecated: Not recommended
pub fn persistentDomainNames(&self) -> Retained<NSArray>
-persistentDomainNames returns an incomplete list of domains that have preferences stored in them.
Sourcepub fn persistentDomainForName(
&self,
domain_name: &NSString,
) -> Option<Retained<NSDictionary<NSString>>>
pub fn persistentDomainForName( &self, domain_name: &NSString, ) -> Option<Retained<NSDictionary<NSString>>>
-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,
)
pub unsafe fn setPersistentDomain_forName( &self, domain: &NSDictionary<NSString>, domain_name: &NSString, )
-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.
§Safety
domain generic should be of the correct type.
Sourcepub fn removePersistentDomainForName(&self, domain_name: &NSString)
pub fn removePersistentDomainForName(&self, domain_name: &NSString)
-removePersistentDomainForName: removes all values from the search list entry specified by ‘domainName’, the current user, and any host. The change is persistent.
Sourcepub fn synchronize(&self) -> bool
pub 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 fn objectIsForcedForKey(&self, key: &NSString) -> bool
pub fn objectIsForcedForKey_inDomain( &self, key: &NSString, domain: &NSString, ) -> bool
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 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