iOS Developer Library — Pre-Release

Developer

Foundation Framework Reference NSMapTable Class Reference

Options
Deployment Target:

On This Page
Language:

NSMapTable

NSMapTable is a mutable collection modeled after NSDictionary but provides different options. More...

Inheritance


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 6.0 and later.
  • Returns a the value associated with a given key.

    Declaration

    Swift

    func objectForKey(_ aKey: AnyObject) -> AnyObject?

    Objective-C

    - (id)objectForKey:(id)aKey

    Parameters

    aKey

    The key for which to return the corresponding value.

    Return Value

    The value associated with aKey, or nil if no value is associated with aKey.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Returns an enumerator object that lets you access each key in the map table.

    Declaration

    Swift

    func keyEnumerator() -> NSEnumerator

    Objective-C

    - (NSEnumerator *)keyEnumerator

    Return Value

    An enumerator object that lets you access each key in the map table.

    Discussion

    The following code fragment illustrates how you might use the method.

    • NSEnumerator *enumerator = [myMapTable keyEnumerator];
    • id value;
    • while ((value = [enumerator nextObject])) {
    • /* code that acts on the map table's keys */
    • }

    Special Considerations

    It is more efficient to use the fast enumeration protocol (see NSFastEnumeration).

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Returns an enumerator object that lets you access each value in the map table.

    Declaration

    Swift

    func objectEnumerator() -> NSEnumerator

    Objective-C

    - (NSEnumerator *)objectEnumerator

    Return Value

    An enumerator object that lets you access each value in the map table.

    Discussion

    The following code fragment illustrates how you might use the method.

    • NSEnumerator *enumerator = [myMapTable objectEnumerator];
    • id value;
    • while ((value = [enumerator nextObject])) {
    • /* code that acts on the map table's values */
    • }

    Special Considerations

    It is more efficient to use the fast enumeration protocol (see NSFastEnumeration).

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • count count Property

    The number of key-value pairs in the map table. (read-only)

    Declaration

    Swift

    var count: Int { get }

    Objective-C

    @property(readonly) NSUInteger count

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Adds a given key-value pair to the map table.

    Declaration

    Swift

    func setObject(_ anObject: AnyObject, forKey aKey: AnyObject)

    Objective-C

    - (void)setObject:(id)anObject forKey:(id)aKey

    Parameters

    anObject

    The value for aKey. This value must not be nil.

    aKey

    The key for anObject. This value must not be nil.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Removes a given key and its associated value from the map table.

    Declaration

    Swift

    func removeObjectForKey(_ aKey: AnyObject)

    Objective-C

    - (void)removeObjectForKey:(id)aKey

    Parameters

    aKey

    The key to remove.

    Discussion

    Does nothing if aKey does not exist.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Empties the map table of its entries.

    Declaration

    Swift

    func removeAllObjects()

    Objective-C

    - (void)removeAllObjects

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.

  • Constants used as components in a bitfield to specify the behavior of elements (keys and values) in an NSMapTable object.

    Declaration

    Swift

    typealias NSMapTableOptions = Int

    Objective-C

    enum { NSMapTableStrongMemory = 0, NSMapTableCopyIn = NSPointerFunctionsCopyIn, NSMapTableObjectPointerPersonality = NSPointerFunctionsObjectPointerPersonality, NSMapTableWeakMemory = NSPointerFunctionsWeakMemory }; typedef NSUInteger NSMapTableOptions;

    Constants

    • NSMapTableStrongMemory

      NSMapTableStrongMemory

      Specifies a strong reference from the map table to its contents.

      Equal to NSPointerFunctionsStrongMemory.

      Available in iOS 6.0 and later.

    • NSMapTableCopyIn

      NSMapTableCopyIn

      Use the memory acquire function to allocate and copy items on input (see acquireFunction [NSPointerFunctions]).

      Equal to NSPointerFunctionsCopyIn.

      Available in iOS 6.0 and later.

    • NSMapTableObjectPointerPersonality

      NSMapTableObjectPointerPersonality

      Use shifted pointer hash and direct equality, object description.

      Equal to NSPointerFunctionsObjectPointerPersonality.

      Available in iOS 6.0 and later.

    • NSMapTableWeakMemory

      NSMapTableWeakMemory

      Uses weak read and write barriers appropriate for ARC or GC. Using NSPointerFunctionsWeakMemory object references will turn to NULL on last release. Equal to NSMapTableZeroingWeakMemory.

      Available in iOS 6.0 and later.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 6.0 and later.