<!--
{
  "availability" : [
    "DriverKit: -",
    "iOS: -",
    "iPadOS: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "DriverKit",
  "identifier" : "/documentation/DriverKit/OSSet/setObject",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "DriverKit"
    ],
    "preciseIdentifier" : "c:@S@OSSet@F@setObject#*1$@S@OSMetaClassBase#"
  },
  "title" : "setObject"
}
-->

# setObject

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

```
bool setObject(const OSMetaClassBase *anObject);
```

## Parameters

`anObject`

The OSMetaClassBase-derived object to be added to the set.

## Return Value

`true` if `anObject` was successfully added to the set, `false` otherwise (including if it was already in the set).

## Discussion

The set adds storage to accomodate the new object, if necessary. If successfully added, the object is retained.

A `false` return value can mean either that `anObject` is already present in the set, or that a memory allocation failure occurred. If you need to know whether the object is already present, use containsObject.

---

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)