---
title: "dictionaryWithObjects:forKeys:count:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsdictionary/dictionarywithobjects:forkeys:count:"
---

# dictionaryWithObjects:forKeys:count:

Creates a dictionary containing a specified number of objects from a C array.

## Declaration

```occ
+ (instancetype) dictionaryWithObjects:(ObjectType const[]) objects forKeys:(id<NSCopying> const[]) keys count:(NSUInteger) cnt;
```

## Parameters

- `objects`: A C array of values for the new dictionary.
- `keys`: A C array of keys for the new dictionary. Each key is copied (using doc://com.apple.foundation/documentation/Foundation/NSCopying/copy(with:); keys must conform to the NSCopying protocol), and the copy is added to the new dictionary.
- `cnt`: The number of elements to use from the keys and objects arrays. cnt must not exceed the number of elements in objects or keys.

## Discussion

Discussion This method steps through the objects and keys arrays, creating entries in the new dictionary as it goes. An NSInvalidArgumentException is raised if a key or value object is nil. The following code fragment illustrates how to create a dictionary that associates the alphabetic characters with their ASCII values: static const NSInteger N_ENTRIES = 26; NSDictionary *asciiDict; NSString *keyArray[N_ENTRIES]; NSNumber *valueArray[N_ENTRIES]; NSInteger i;   for (i = 0; i < N_ENTRIES; i++) {       char charValue = 'a' + i;     keyArray[i] = [NSString stringWithFormat:@"%c", charValue];     valueArray[i] = [NSNumber numberWithChar:charValue]; }   asciiDict = [NSDictionary dictionaryWithObjects:(id *)valueArray                           forKeys:(id *)keyArray count:N_ENTRIES];

## See Also

### Creating a Dictionary from Objects and Keys

- [dictionaryWithObjects:forKeys:](foundation/nsdictionary/dictionarywithobjects:forkeys:.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)
- [initWithObjectsAndKeys:](foundation/nsdictionary/initwithobjectsandkeys:.md)
- [init(object:forKey:)](foundation/nsdictionary/init(object:forkey:).md)
