<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCountedSet/init(capacity:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCountedSet(im)initWithCapacity:"
  },
  "title" : "init(capacity:)"
}
-->

# init(capacity:)

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

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

## Parameters

`numItems`

The initial capacity of the new counted set.

## Return Value

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

## Discussion

The method is the designated initializer for [`NSCountedSet`](/documentation/Foundation/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

[`+  setWithCapacity:`](/documentation/Foundation/NSMutableSet/setWithCapacity:)

Creates and returns a mutable set with a given initial capacity.

[`-  initWithCapacity:`](/documentation/Foundation/NSMutableSet/init(capacity:))

Returns an initialized mutable set with a given initial capacity.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)