dictionaryWithObject :forKey:
Creates and returns a dictionary containing a given key and value.
Parameters of [NSDictionary dictionaryWithObject]
- anObject
- The value corresponding to aKey.If this value is
nil
, anNSInvalidArgumentException
is raised. - aKey
- The key for anObject.If this value is
nil
, anNSInvalidArgumentException
is raised.
Return Value
A new dictionary containing a single object, anObject, for a single key, aKey.
Example of [NSDictionary dictionaryWithObject]
NSArray *keys = [NSArray arrayWithObjects:@"key1", @"key2", nil];
NSArray *objects = [NSArray arrayWithObjects:@"value1", @"value2", nil];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects
forKeys:keys];
Example of [NSDictionary dictionaryWithObject]
NSObject * obj = [[NSObject alloc] init];
NSDictionary * dict = [NSDictionary dictionaryWithObject :obj forKey:@"test"];