initWithObjectsAndKeys:
Initializes a newly allocated dictionary with entries constructed from the specified set of values and keys.
- (id)initWithObjectsAndKeys:(id)firstObject , ...
Parameters
- firstObject
- The first value to add to the new dictionary.
- ...
- First the key for firstObject, then a null-terminated list of alternating values and keys. If any key is
nil
, anNSInvalidArgumentException
is raised.
Discussion of [NSDictionary initWithObjectsAndKeys]
This method is similar to
initWithObjects:forKeys:
, differing only in the way in which the key-value pairs are specified.
Example of [NSDictionary initWithObjectsAndKeys]
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
|
@"value1", @"key1", @"value2", @"key2", nil];
|
Example of [NSDictionary initWithObjectsAndKeys]
NSDictionary *qDictionary = [[NSDictionary alloc]
initWithObjectsAndKeys:question,@"questionText",
[NSNumber numberWithInteger:questionId],@"questionId",
[NSNumber numberWithBool:userAnswer],@"userAnswer",
[NSNumber numberWithBool:correctAnswer],@"correctAnswer",
nil];
Example of [NSDictionary initWithObjectsAndKeys]
self.originalValues = [[NSDictionary alloc] initWithObjectsAndKeys:
place.city ?: [NSNull null], @"city",
place.cuisine ?: [NSNull null], @"cuisine",
place.latitude ?: [NSNull null], @"latitude",
place.longitude ?: [NSNull null], @"longitude",
place.name ?: [NSNull null], @"name",
place.rating ?: [NSNull null], @"rating",
place.state ?: [NSNull null], @"state",
place.street ?: [NSNull null], @"street",
place.telephone ?: [NSNull null], @"telephone",
place.timesVisited ?: [NSNull null], @"times visited",
place.uppercaseFirstLetterOfName ?: [NSNull null], @"first letter",
place.website ?: [NSNull null], @"website",
place.zipcode ?: [NSNull null], @"zipcode",
nil];