<!--
{
  "availability" : [
    "DriverKit: -",
    "iOS: -",
    "iPadOS: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "DriverKit",
  "identifier" : "/documentation/DriverKit/OSSet",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "DriverKit"
    ],
    "preciseIdentifier" : "c:@S@OSSet"
  },
  "title" : "OSSet"
}
-->

# OSSet

OSSet provides an unordered set store of objects.

```
class OSSet;
```

## Overview

OSSet is a container for Libkern C++ objects (those derived from [`OSMetaClassBase`](/documentation/DriverKit/OSMetaClassBase), in particular [`OSObject`](/documentation/DriverKit/OSObject)). Storage and access follow basic set logic: you can add or remove an object, and test whether the set contains a particular object. A given object is only stored in the set once, and there is no ordering of objects in the set. A subclass [`OSOrderedSet`](/documentation/DriverKit/OSOrderedSet), provides for ordered set logic.

As with all Libkern collection classes, OSSet retains objects added to it, and releases objects removed from it. An OSSet also grows as necessary to accommodate new objects, unlike Core Foundation collections (it does not, however, shrink).

## Use Restrictions

With very few exceptions in the I/O Kit, all Libkern-based C++ classes, functions, and macros are unsafe to use in a primary interrupt context. Consult the I/O Kit documentation related to primary interrupts for more information.

OSSet provides no concurrency protection; it’s up to the usage context to provide any protection necessary. Some portions of the I/O Kit, such as `IORegistryEntry`, handle synchronization via defined member functions for setting properties.

## Topics

### Instance Methods

[`bool containsObject(const OSMetaClassBase *anObject) const;`](/documentation/DriverKit/OSSet/containsObject)

[`OSObject * getAnyObject() const;`](/documentation/DriverKit/OSSet/getAnyObject)

Returns an arbitrary (not random) object from the set.

[`virtual bool init();`](/documentation/DriverKit/OSSet/init)

[`bool member(const OSMetaClassBase *anObject) const;`](/documentation/DriverKit/OSSet/member)

Checks the set for the presence of an object.

[`bool merge(const OSArray *otherArray);`](/documentation/DriverKit/OSSet/merge)

Adds the contents of an OSet to the set.

[`void removeObject(const OSMetaClassBase *anObject);`](/documentation/DriverKit/OSSet/removeObject)

[`bool setObject(const OSMetaClassBase *anObject);`](/documentation/DriverKit/OSSet/setObject)

Adds an object to the OSSet if it is not already present.

### Type Methods

[`static OSSetPtr withArray(const OSArray *array, uint32_t capacity);`](/documentation/DriverKit/OSSet/withArray)

Creates and initializes an OSSet populated with the contents of an OSArray.

[`static OSSetPtr withCapacity(uint32_t capacity);`](/documentation/DriverKit/OSSet/withCapacity)

[`static OSSetPtr withObjects(const OSObject **values, uint32_t count, uint32_t capacity);`](/documentation/DriverKit/OSSet/withObjects)

Creates and initializes an OSSet populated with objects provided.

## Relationships

### Inherits From

[`OSArray`](/documentation/DriverKit/OSArray)

### Inherited By

[`OSOrderedSet`](/documentation/DriverKit/OSOrderedSet)

---

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)