---
title: "initWithObjectsAndKeys:"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdictionary/initwithobjectsandkeys:"
---

# initWithObjectsAndKeys:

Initializes a newly allocated dictionary with entries constructed from the specified set of values and keys.

## Declaration

```occ
- (instancetype) initWithObjectsAndKeys:(id) firstObject;
```

## Parameters

- `firstObject`: The first value to add to the new dictionary.

## Discussion

Discussion After the firstObject value, pass the key for firstObject, then a null-terminated list of alternating values and keys. If any key is nil, an invalidArgumentException is raised. This method is similar to init(objects:forKeys:), differing only in the way in which the key-value pairs are specified. For example: NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:     @"value1", @"key1", @"value2", @"key2", nil];

## See Also

### Creating a Dictionary from Objects and Keys

- [dictionaryWithObjects:forKeys:](foundation/nsdictionary/dictionarywithobjects:forkeys:.md)
- [dictionaryWithObjects:forKeys:count:](foundation/nsdictionary/dictionarywithobjects:forkeys:count:.md)
- [init(objects:forKeys:)](foundation/nsdictionary/init(objects:forkeys:).md)
- [init(objects:forKeys:count:)](foundation/nsdictionary/init(objects:forkeys:count:).md)
- [dictionaryWithObjectsAndKeys:](foundation/nsdictionary/dictionarywithobjectsandkeys:.md)
- [init(object:forKey:)](foundation/nsdictionary/init(object:forkey:).md)
