Platforms to show: All Mac Windows Linux Cross-Platform

Back to CFDictionaryMBS class.

CFDictionaryMBS.clone as CFDictionaryMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin ✅ Yes ❌ No ❌ No ✅ Yes All
Clones the dictionary and all values.

CFDictionaryMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin 10.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new editable dictionary.
Example
dim m as new CFMutableDictionaryMBS
m.Add(NewCFStringMBS("Key"), NewCFStringMBS("value"))
MsgBox str(m.Count)

See also:

CFDictionaryMBS.Constructor(dic as dictionary)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin 10.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a new CFDictionary based on the Xojo Dictionary.
Example
// build a dictionary
dim d as new Dictionary

d.Value("Hello")=2
d.Value("test")="World"
d.Value("ddd")=5.6

// convert to CFDictionary
dim c as new CFDictionaryMBS(d)

// Display as XML
dim b as CFBinaryDataMBS = c.XML
MsgBox b.str

// now convert back
dim e as Dictionary = c.dictionary

// and display values
for each key as Variant in e.keys
MsgBox key+" -> "+e.Value(key)
next

Be aware that the Dictionary is converted as good as possible. Unsupported datatype will be missing.

See the FAQ for the supported type translation between CoreFoundation and Xojo data types.

See also:

CFDictionaryMBS.ContainsKey(value as CFObjectMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin ✅ Yes ❌ No ❌ No ✅ Yes All
Does the dictionary contain this key?
Example
dim c as CFMutableDictionaryMBS = NewCFMutableDictionaryMBS

c.Add NewCFStringMBS("test"),NewCFStringMBS("Value")

MsgBox c.XML.Str

if c.ContainsKey(NewCFStringMBS("test")) then
MsgBox "OK"
else
MsgBox "Failed"
end if

if c.ContainsKey(NewCFStringMBS("missing")) then
MsgBox "Failed"
else
MsgBox "OK"
end if

CFDictionaryMBS.ContainsValue(value as CFObjectMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin ✅ Yes ❌ No ❌ No ✅ Yes All
Does the dictionary contain this value?

CFDictionaryMBS.CountKey(value as CFObjectMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin ✅ Yes ❌ No ❌ No ✅ Yes All
Counts how often this key is inside the dictionary.

CFDictionaryMBS.CountValue(value as CFObjectMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin ✅ Yes ❌ No ❌ No ✅ Yes All
Counts how often this value is inside the dictionary.

CFDictionaryMBS.Dictionary as Dictionary

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin 10.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a Xojo Dictionary from this CFDictionary.
Example
// build a dictionary
dim d as new Dictionary

d.Value("Hello")=2
d.Value("test")="World"
d.Value("ddd")=5.6

// convert to CFDictionary
dim c as new CFDictionaryMBS(d)

// Display as XML
dim b as CFBinaryDataMBS = c.XML
MsgBox b.str

// now convert back
dim e as Dictionary = c.dictionary

// and display values
for each key as Variant in e.keys
MsgBox key+" -> "+e.Value(key)
next

Be aware that the CFDictionary is converted as good as possible. Unsupported datatype will be missing.

See the FAQ for the supported type translation between CoreFoundation and Xojo data types.

CFDictionaryMBS.edit as CFMutableDictionaryMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin ✅ Yes ❌ No ❌ No ✅ Yes All
To edit a dictionary, this method returns you a CFMutableDictionaryMBS.

CFDictionaryMBS.list as CFDictionaryListMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin ✅ Yes ❌ No ❌ No ✅ Yes All
Returns a list of all values.

This list will be invalid whenever this dictionary is destroyed.

CFDictionaryMBS.Value(key as CFObjectMBS) as CFObjectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin ✅ Yes ❌ No ❌ No ✅ Yes All
If the key is found the value for this key is returned.

Returns nil if key is not found.

CFDictionaryMBS.writeToFile(file as folderitem, useAuxiliaryFile as boolean) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin 10.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Writes a property list representation of the contents of the receiver to a given path.
Example
dim m as new CFMutableDictionaryMBS

m.Set(NewCFStringMBS("key"), NewCFStringMBS("value"))

dim f as FolderItem = SpecialFolder.Desktop.Child("test.plist")

if m.writeToFile(f, true) then
MsgBox "OK"
else
MsgBox "Failed"
end if

path: The path at which to write the file. Must be an absolute URL.
useAuxiliaryFile: A flag that specifies whether the file should be written atomically.

If flag is true, the receiver is written to an auxiliary file, and then the auxiliary file is renamed to path. If flag is false, the dictionary is written directly to path. The true option guarantees that path, if it exists at all, won't be corrupted even if the system should crash during writing.

Returns true if the file is written successfully, otherwise false.

This method recursively validates that all the contained objects are property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary) before writing out the file, and returns false if all the objects are not property list objects, since the resultant file would not be a valid property list.

If the receiver's contents are all property list objects, the file written by this method can be used to initialize a new dictionary with the class method dictionaryWithContentsOfFile or dictionaryWithContentsOfURL.

CFDictionaryMBS.writeToURL(url as string, atomically as boolean) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method CoreFoundation MBS MacCF Plugin 10.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Writes a property list representation of the contents of the receiver to a given URL.
Example
dim m as new CFMutableDictionaryMBS

m.Set(NewCFStringMBS("key"), NewCFStringMBS("value"))

dim f as FolderItem = SpecialFolder.Desktop.Child("test.plist")

if m.writeTourl(f.URLPath, true) then
MsgBox "OK"
else
MsgBox "Failed"
end if

url: The URL to which to write the receiver.
atomically: A flag that specifies whether the output should be written atomically.

If flag is YtrueES, the receiver is written to an auxiliary location, and then the auxiliary location is renamed to aURL. If flag is false, the dictionary is written directly to aURL. The true option guarantees that aURL, if it exists at all, won't be corrupted even if the system should crash during writing. flag is ignored if aURL is of a type that cannot be written atomically.

Returns true if the location is written successfully, otherwise false.

This method recursively validates that all the contained objects are property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary) before writing out the file, and returns false if all the objects are not property list objects, since the resultant output would not be a valid property list.

If the receiver's contents are all property list objects, the location written by this method can be used to initialize a new dictionary with the class method dictionaryWithContentsOfURL or dictionaryWithContentsOfFile.

For more information about property lists, see Property List Programming Guide.

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


The biggest plugin in space...