<!--
{
  "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/NSMutableSet/init(capacity:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableSet(im)initWithCapacity:"
  },
  "title" : "init(capacity:)"
}
-->

# init(capacity:)

Returns an initialized mutable set with a given initial capacity.

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

## Parameters

`numItems`

The initial capacity of the set.

## Return Value

An initialized mutable set with initial capacity to hold `numItems` members. The returned set might be different than the original receiver.

## Discussion

Mutable sets allocate additional memory as needed, so `numItems` simply establishes the object’s initial capacity.

This method is a designated initializer for `NSMutableSet`.

## See Also

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

Creates and returns a 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)