/* NSDictionary.h Copyright (c) 1994-2012, Apple Inc. All rights reserved. */ #import #import @class NSArray, NSSet, NSString, NSURL; /**************** Immutable Dictionary ****************/ @interface NSDictionary : NSObject - (NSUInteger)count; - (id)objectForKey:(id)aKey; - (NSEnumerator *)keyEnumerator; @end @interface NSDictionary (NSExtendedDictionary) - (NSArray *)allKeys; - (NSArray *)allKeysForObject:(id)anObject; - (NSArray *)allValues; - (NSString *)description; - (NSString *)descriptionInStringsFileFormat; - (NSString *)descriptionWithLocale:(id)locale; - (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level; - (BOOL)isEqualToDictionary:(NSDictionary *)otherDictionary; - (NSEnumerator *)objectEnumerator; - (NSArray *)objectsForKeys:(NSArray *)keys notFoundMarker:(id)marker; - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile; - (BOOL)writeToURL:(NSURL *)url atomically:(BOOL)atomically; // the atomically flag is ignored if url of a type that cannot be written atomically. - (NSArray *)keysSortedByValueUsingSelector:(SEL)comparator; - (void)getObjects:(id __unsafe_unretained [])objects andKeys:(id __unsafe_unretained [])keys; - (id)objectForKeyedSubscript:(id)key NS_AVAILABLE(10_8, 6_0); #if NS_BLOCKS_AVAILABLE - (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))block NS_AVAILABLE(10_6, 4_0); - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(id key, id obj, BOOL *stop))block NS_AVAILABLE(10_6, 4_0); - (NSArray *)keysSortedByValueUsingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0); - (NSArray *)keysSortedByValueWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr NS_AVAILABLE(10_6, 4_0); - (NSSet *)keysOfEntriesPassingTest:(BOOL (^)(id key, id obj, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0); - (NSSet *)keysOfEntriesWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id key, id obj, BOOL *stop))predicate NS_AVAILABLE(10_6, 4_0); #endif @end @interface NSDictionary (NSDictionaryCreation) + (id)dictionary; + (id)dictionaryWithObject:(id)object forKey:(id )key; #if TARGET_OS_WIN32 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(NSUInteger)cnt; #else + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(NSUInteger)cnt; #endif + (id)dictionaryWithObjectsAndKeys:(id)firstObject, ... NS_REQUIRES_NIL_TERMINATION; + (id)dictionaryWithDictionary:(NSDictionary *)dict; + (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; #if TARGET_OS_WIN32 - (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(NSUInteger)cnt; #else - (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(NSUInteger)cnt; #endif - (id)initWithObjectsAndKeys:(id)firstObject, ... NS_REQUIRES_NIL_TERMINATION; - (id)initWithDictionary:(NSDictionary *)otherDictionary; - (id)initWithDictionary:(NSDictionary *)otherDictionary copyItems:(BOOL)flag; - (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; + (id)dictionaryWithContentsOfFile:(NSString *)path; + (id)dictionaryWithContentsOfURL:(NSURL *)url; - (id)initWithContentsOfFile:(NSString *)path; - (id)initWithContentsOfURL:(NSURL *)url; @end /**************** Mutable Dictionary ****************/ @interface NSMutableDictionary : NSDictionary - (void)removeObjectForKey:(id)aKey; - (void)setObject:(id)anObject forKey:(id )aKey; @end @interface NSMutableDictionary (NSExtendedMutableDictionary) - (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary; - (void)removeAllObjects; - (void)removeObjectsForKeys:(NSArray *)keyArray; - (void)setDictionary:(NSDictionary *)otherDictionary; - (void)setObject:(id)obj forKeyedSubscript:(id )key NS_AVAILABLE(10_8, 6_0); @end @interface NSMutableDictionary (NSMutableDictionaryCreation) + (id)dictionaryWithCapacity:(NSUInteger)numItems; - (id)initWithCapacity:(NSUInteger)numItems; @end @interface NSDictionary (NSSharedKeySetDictionary) /* Use this method to create a key set to pass to +dictionaryWithSharedKeySet:. The keys are copied from the array and must be copyable. If the array parameter is nil or not an NSArray, an exception is thrown. If the array of keys is empty, an empty key set is returned. The array of keys may contain duplicates, which are ignored (it is undefined which object of each duplicate pair is used). As for any usage of hashing, is recommended that the keys have a well-distributed implementation of -hash, and the hash codes must satisfy the hash/isEqual: invariant. Keys with duplicate hash codes are allowed, but will cause lower performance and increase memory usage. */ + (id)sharedKeySetForKeys:(NSArray *)keys NS_AVAILABLE(10_8, 6_0); @end @interface NSMutableDictionary (NSSharedKeySetDictionary) /* Create a mutable dictionary which is optimized for dealing with a known set of keys. Keys that are not in the key set can still be set into the dictionary, but that usage is not optimal. As with any dictionary, the keys must be copyable. If keyset is nil, an exception is thrown. If keyset is not an object returned by +sharedKeySetForKeys:, an exception is thrown. */ + (id)dictionaryWithSharedKeySet:(id)keyset NS_AVAILABLE(10_8, 6_0); @end