Thursday, May 9, 2013

NSDictionary initWithObjectsAndKeys example ios


Initializes a newly allocated dictionary with entries constructed from the specified set of values and keys.
- (id)initWithObjectsAndKeys:(id)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]
                           [NSNumber numberWithInteger:questionId],@"questionId",
                           [NSNumber numberWithBool:userAnswer],@"userAnswer",
                           [NSNumber numberWithBool:correctAnswer],@"correctAnswer",
Example of [NSDictionary initWithObjectsAndKeys]
self.originalValues = [[NSDictionary alloc] initWithObjectsAndKeys:
                ?: [NSNull null], @"city",
                         place.cuisine ?: [NSNull null], @"cuisine",
                         place.latitude ?: [NSNull null], @"latitude",
                         place.longitude ?: [NSNull null], @"longitude",
                ?: [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", 
                ?: [NSNull null], @"website",
                         place.zipcode ?: [NSNull null], @"zipcode",