CFSet
Declaration
class CFSetOverview
CFSet and its derived mutable type, CFMutableSet, provide support for the mathematical concept of a set. A set, both in its mathematical sense and in the implementation of CFSet, is an unordered collection of distinct elements. CFSet creates static sets and CFMutableSet creates dynamic sets.
Use bags or sets as an alternative to arrays when the order of elements isn’t important and performance in testing whether a value is contained in the collection is a consideration—while arrays are ordered, testing for membership is slower than with bags or sets. Use bags over sets if you want to allow duplicate values in your collections.
You create a static set object using either the CFSetCreate(_:_:_:_:) or CFSetCreateCopy(_:_:) function. These functions return a set containing the values you pass in as arguments. (Note that sets can’t contain NULL pointers; in most cases, though, you can use the kCFNull constant instead.) Values are not copied but retained using the retain callback provided when the set was created. Similarly, when a value is removed from a set, it is released using the release callback.
CFSet provides functions for querying the values of a set. The CFSetGetCount(_:) returns the number of values in a set, the CFSetContainsValue(_:_:) function checks if a value is in a set, and CFSetGetValues(_:_:) returns a C array containing all the values in a set.
CFSet is “toll-free bridged” with its Cocoa Foundation counterpart, NSSet. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSSet * parameter, you can pass in a CFSetRef, and in a function where you see a CFSetRef parameter, you can pass in an NSSet instance. This also applies to concrete subclasses of NSSet. See Toll-Free Bridged Types for more information on toll-free bridging.
Topics
Creating Sets
Examining a Set
CFSetContainsValue(_:_:)CFSetGetCount(_:)CFSetGetCountOfValue(_:_:)CFSetGetValue(_:_:)CFSetGetValueIfPresent(_:_:_:)CFSetGetValues(_:_:)
Applying a Function to Set Members
Getting the CFSet Type ID
Callbacks
CFSetApplierFunctionCFSetCopyDescriptionCallBackCFSetEqualCallBackCFSetHashCallBackCFSetReleaseCallBackCFSetRetainCallBack
Data Types
Constants
See Also
Related Documentation
- Collections Programming Topics for Core Foundation