---
title: "init(capacity:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nscountedset/init(capacity:)"
---

# init(capacity:)

Returns a counted set object initialized with enough memory to hold a given number of objects.

## Declaration

```swift
init(capacity numItems: Int)
```

## Parameters

- `numItems`: The initial capacity of the new counted set.

## Return Value

Return Value A counted set object initialized with enough memory to hold numItems objects

## Discussion

Discussion The method is the designated initializer for NSCountedSet. Note that the capacity is simply a hint to help initial memory allocation—the initial count of the object is 0, and the set still grows and shrinks as you add and remove objects. The hint is typically useful if the set will become large.

## See Also

### Related Documentation

- [init(capacity:)](foundation/nsmutableset/init(capacity:).md)

### Initializing a Counted Set

- [init(array:)](foundation/nscountedset/init(array:).md)
- [init(set:)](foundation/nscountedset/init(set:).md)
