Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSUserDefaultsMBS class.

Next items

NSUserDefaultsMBS.addSuiteNamed(suiteName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Inserts the specified domain name into the receiver's search list.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.addSuiteNamed "testsuite"

suiteName: The domain name to insert. This domain is inserted after the application domain.

The suiteName domain is similar to a bundle identifier string, but is not tied to a particular application or bundle. A suite can be used to hold preferences that are shared between multiple applications.

Some examples using this method:

NSUserDefaultsMBS.arrayForKey(key as string) as Variant()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the array associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
dim t(-1) as Variant
t.Append "Hello"
t.Append "World"

u.setArrayValue "test", t

dim a(-1) as Variant = u.ArrayForKey("test")

for each v as Variant in a
MsgBox v
next

The array associated with the specified key, or an empty array if the key does not exist or its value is not an array.

NSUserDefaultsMBS.boolForKey(key as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The Boolean value associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.boolForKey("test") = true
MsgBox str(u.boolForKey("test"))

If a boolean value is associated with defaultName in the user defaults, that value is returned. Otherwise, false is returned.
(Read and Write computed property)

NSUserDefaultsMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new user defaults object initialized with the defaults for the current user account.
Example
dim u as new NSUserDefaultsMBS
u.setURLValue "test", "http://www.apple.de/"
MsgBox u.URLForKey("test")

This method does not put anything in the search list.

See also:

NSUserDefaultsMBS.Constructor(username as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates an NSUserDefaultsMBS object initialized with the defaults for the specified user account.

username: The name of the user account.

Returns an initialized NSUserDefaultsMBS object whose argument and registration domains are already set up. If the current user does not have access to the specified user account, the object is invalid.

This method does not put anything in the search list. Invoke it only if you've allocated your own NSUserDefaults instance instead of using the shared one.

You do not normally use this method to initialize an instance of NSUserDefaults. Applications used by a superuser might use this method to update the defaults databases for a number of users. The user who started the application must have appropriate access (read, write, or both) to the defaults database of the new user, or this method returns nil.

See also:

NSUserDefaultsMBS.dataForKey(key as string) as memoryblock

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The data string associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults

u.dataForKey("test")="Hello äöü"

MsgBox u.dataForKey("test") // shows no umlauts as encoding is away in binary string

Returns the memoryblock or nil if there is no value for this key.

dataForKey is for any string and does not store encoding. stringForKey does store encoding and works only for text strings.
(Read and Write computed property)

NSUserDefaultsMBS.dictionaryForKey(key as string) as dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The dictionary object associated with the specified key.
Example
dim u as new NSUserDefaultsMBS
dim d as new Dictionary

d.Value("First")="Hello"
d.Value("Second")=1234.5678
u.setDictionaryValue "test", d

dim e as Dictionary = u.dictionaryForKey("test")
for each key as Variant in e.keys
dim value as Variant = e.Value(key)
MsgBox key+": "+value
next

Returns dictionary object associated with the specified key, or nil if the key does not exist or its value is not an dictionary.
(Read and Write computed property)

NSUserDefaultsMBS.dictionaryRepresentation as dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a dictionary that contains a union of all key-value pairs in the domains in the search list.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
dim d as Dictionary = u.dictionaryRepresentation

break // "Look here in the dictionary in the debugger."

Returns a dictionary containing the keys. The keys are names of defaults and the value corresponding to each key is a property list object as Variant.

As with variantForKey, key-value pairs in domains that are earlier in the search list take precedence. The combined result does not preserve information about which domain each entry came from.

NSUserDefaultsMBS.doubleForKey(key as string) as Double

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The double value associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.doubleForKey("test") = 5
MsgBox str(u.doubleForKey("test"))

Returns the double value associated with the specified key. If the key does not exist, this method returns 0.
Available in Mac OS X v10.5 and later. On Mac OS X 10.4 the plugin will call floatForKey for you to avoid an exception.
(Read and Write computed property)

NSUserDefaultsMBS.fileForKey(key as string) as folderitem

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The NSURL instance associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
dim f as FolderItem = SpecialFolder.Desktop

// write
u.fileForKey("test")=f

// read
MsgBox u.fileForKey("test").NativePath

Available in Mac OS X v10.6 and later.
(Read and Write computed property)

NSUserDefaultsMBS.floatForKey(key as string) as single

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The floating-point value associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.floatForKey("test") = 5
MsgBox str(u.floatForKey("test"))

Returns the floating-point value associated with the specified key. If the key does not exist, this method returns 0.
(Read and Write computed property)

NSUserDefaultsMBS.integerForKey(key as string) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The integer value associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.IntegerForKey("test") = 5
MsgBox str(u.integerForKey("test"))

The integer value associated with the specified key. If the specified key does not exist, this method returns 0.
(Read and Write computed property)

Some examples using this property:

NSUserDefaultsMBS.objectIsForcedForKey(key as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value indicating whether the specified key is managed by an administrator.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
MsgBox str(u.objectIsForcedForKey("test"))

key: The key whose status you want to check.

Returns true if the value of the specified key is managed by an administrator, otherwise false.

This method assumes that the key is a preference associated with the current user and application. For managed keys, the application should disable any user interface that allows the user to modify the value of key.

Available in Mac OS X v10.2 and later.

See also:

NSUserDefaultsMBS.objectIsForcedForKey(key as string, domain as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a Boolean value indicating whether the key in the specified domain is managed by an administrator.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
MsgBox str(u.objectIsForcedForKey("test", u.NSGlobalDomain))

key: The key whose status you want to check.
domain: The domain of the key.

Returns true if the key is managed by an administrator in the specified domain, otherwise false.

This method assumes that the key is a preference associated with the current user. For managed keys, the application should disable any user interface that allows the user to modify the value of key.

Available in Mac OS X v10.2 and later.

See also:

NSUserDefaultsMBS.persistentDomainForName(domainName as string) as dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a dictionary containing the keys and values in the specified persistent domain.

Returns a dictionary containing the keys. The keys are names of defaults and the value corresponding to each key is a property list object (NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary).

NSUserDefaultsMBS.persistentDomainNames as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns an array of the current persistent domain names.

You can get the keys and values for each domain by passing the returned domain names to the persistentDomainForName method.

NSUserDefaultsMBS.registerDefaults(dic as dictionary)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Adds the contents the specified dictionary to the registration domain.

dic: The dictionary of keys and values you want to register.

If there is no registration domain, one is created using the specified dictionary, and NSRegistrationDomain is added to the end of the search list.

The contents of the registration domain are not written to disk; you need to call this method each time your application starts. You can place a plist file in the application's Resources directory and call registerDefaults with the contents that you read in from that file.

Some examples using this method:

NSUserDefaultsMBS.removeObjectForKey(defaultName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the value of the specified default key in the standard application domain.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setBoolValue("test", true)
u.removeObjectForKey "test"
MsgBox str(u.boolForKey("test")) // shows false as key does not exist

defaultName: The key whose value you want to remove.

Removing a default has no effect on the value returned by the variantForKey method if the same key exists in a domain that precedes the standard application domain in the search list.

NSUserDefaultsMBS.removePersistentDomainForName(domainName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the contents of the specified persistent domain from the user's defaults.

domainName: The domain whose keys and values you want. This value should be equal to your application's bundle identifier.

When a persistent domain is changed, an NSUserDefaultsDidChangeNotification is posted.

NSUserDefaultsMBS.removeSuiteNamed(suiteName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the specified domain name from the receiver's search list.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.removeSuiteNamed "testsuite"

suiteName: The domain name to remove.

NSUserDefaultsMBS.removeVolatileDomainForName(domainName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Removes the specified volatile domain from the user's defaults.

domainName: The volatile domain you want to remove.

NSUserDefaultsMBS.setArrayValue(key as string, values() as Variant)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified array.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
dim t(-1) as Variant
t.Append "Hello"
t.Append "World"

u.setArrayValue "test", t

dim a(-1) as Variant = u.ArrayForKey("test")

for each v as Variant in a
MsgBox v
next

NSUserDefaultsMBS.setBoolValue(key as string, value as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified Boolean value.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setBoolValue("test", true)
MsgBox str(u.boolForKey("test"))

Some examples using this method:

NSUserDefaultsMBS.setDataValue(key as string, value as memoryblock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified binary string.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults

u.setDataValue("test", "Hello äöü")

MsgBox u.dataForKey("test") // shows no umlauts as encoding is away in binary string

setStringValue is for text with encoding and setDataValue is for strings containing binary data.

NSUserDefaultsMBS.setDictionaryValue(key as string, value as dictionary)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified dictionary.
Example
dim u as new NSUserDefaultsMBS
dim d as new Dictionary

d.Value("First")="Hello"
d.Value("Second")=1234.5678
u.setDictionaryValue "test", d

dim e as Dictionary = u.dictionaryForKey("test")
for each key as Variant in e.keys
dim value as Variant = e.Value(key)
MsgBox key+": "+value
next

NSUserDefaultsMBS.setDoubleValue(key as string, value as Double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the double value.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setDoubleValue("test", 5)
MsgBox str(u.DoubleForKey("test"))

Available in Mac OS X v10.5 and later. On Mac OS X 10.4 the plugin will call setFloatValue for you to avoid an exception.

NSUserDefaultsMBS.setFileValue(key as string, value as folderitem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified URL.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
dim f as FolderItem = SpecialFolder.Desktop

// write
u.setFileValue "test", f

// read
MsgBox u.fileForKey("test").NativePath

Available in Mac OS X v10.6 and later.

NSUserDefaultsMBS.setFloatValue(key as string, value as single)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified floating-point value.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setFloatValue("test", 5)
MsgBox str(u.FloatForKey("test"))

NSUserDefaultsMBS.setIntegerValue(key as string, value as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified integer value.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setIntegerValue("test", 5)
MsgBox str(u.integerForKey("test"))

Some examples using this method:

NSUserDefaultsMBS.setPersistentDomain(domain as dictionary, domainName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the dictionary for the specified persistent domain.

domain: The dictionary of keys and values you want to assign to the domain.
domainName: The domain whose keys and values you want to set. This value should be equal to your application's bundle identifier.

When a persistent domain is changed, an NSUserDefaultsDidChangeNotification is posted.

NSUserDefaultsMBS.setStringArrayValue(key as string, values() as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified string array.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
dim t(-1) as string = array("Hello","World")

u.setStringArrayValue "test", t

dim a(-1) as string = u.stringArrayForKey("test")

MsgBox Join(a) // shows "Hello World"

NSUserDefaultsMBS.setStringValue(key as string, value as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified text string.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults

u.setStringValue "test", "Hello äöü"

MsgBox u.stringForKey("test")

setStringValue is for text with encoding and setDataValue is for strings containing binary data.

NSUserDefaultsMBS.setURLValue(key as string, value as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key to the specified URL.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setURLValue "test", "http://www.apple.de/"
MsgBox u.URLForKey("test")

Available in Mac OS X v10.6 and later.

NSUserDefaultsMBS.setVariantValue(key as string, value as Variant)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the value of the specified default key in the standard application domain.
Example
dim u as new NSUserDefaultsMBS
u.setVariantValue "test", "Hello World"
MsgBox u.variantForKey("test")

The value parameter can be only property list objects: String, Number, Date, an Array of variant, or Dictionary. For Arrays and Dictionaries, their contents must be property list objects.

Setting a default has no effect on the value returned by the objectForKey: method if the same key exists in a domain that precedes the application domain in the search list.

NSUserDefaultsMBS.setVolatileDomain(domain as dictionary, domainName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the dictionary for the specified volatile domain.

domain: The dictionary of keys and values you want to assign to the domain.
domainName: The domain whose keys and values you want to set.

This method raises an NSInvalidArgumentException if a volatile domain with the specified name already exists.

NSUserDefaultsMBS.stringArrayForKey(key as string) as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the array of strings associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
dim t(-1) as string = array("Hello","World")

u.setStringArrayValue "test", t

dim a(-1) as string = u.stringArrayForKey("test")

MsgBox Join(a) // shows "Hello World"

Returns an array with strings. The array is empty if the value for the key is not an array.

NSUserDefaultsMBS.stringForKey(key as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The string associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults

u.setStringValue "test", "Hello äöü"

MsgBox u.stringForKey("test")

Returns the string or "" if there is no value for this key.

dataForKey is for any string and does not store encoding. stringForKey does store encoding and works only for text strings.
(Read and Write computed property)

NSUserDefaultsMBS.synchronize as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Writes any modifications to the persistent domains to disk and updates all unmodified persistent domains to what is on disk.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults

// do something

if u.synchronize then
MsgBox "Saved preferences."
else
MsgBox "Failed to save preferences."
end if

Returns true if the data was saved successfully to disk, otherwise false.

Because this method is automatically invoked at periodic intervals, use this method only if you cannot wait for the automatic synchronization (for example, if your application is about to exit) or if you want to update the user defaults to what is on disk even though you have not made any changes.

NSUserDefaultsMBS.URLForKey(key as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The NSURL instance associated with the specified key.
Example
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setURLValue "test", "http://www.apple.de/"
MsgBox u.URLForKey("test")

Available in Mac OS X v10.6 and later.
(Read and Write computed property)

NSUserDefaultsMBS.variantForKey(key as string) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Cocoa MBS MacBase Plugin 10.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The object associated with the first occurrence of the specified default.
Example
dim u as new NSUserDefaultsMBS
u.setVariantValue "test", "Hello World"
MsgBox u.variantForKey("test")

This method searches the domains included in the search list in the order they are listed.
(Read and Write computed property)

Next items

The items on this page are in the following plugins: MBS MacBase Plugin.


The biggest plugin in space...