---
title: setObject
framework: kernel
role: pseudoSymbol
path: kernel/osset/1808269-setobject
---

# setObject

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

## Declaration

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

## Parameters

- `anObject`: The OSMetaClassBase-derived object to be added to the set.

## Return Value

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

## Overview

Overview 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.

## See Also

### Miscellaneous

- [containsObject](kernel/osset/1808031-containsobject.md)
- [copyCollection](kernel/osset/1808046-copycollection.md)
- [ensureCapacity](kernel/osset/1808068-ensurecapacity.md)
- [flushCollection](kernel/osset/1808084-flushcollection.md)
- [free](kernel/osset/1808104-free.md)
- [getAnyObject](kernel/osset/1808128-getanyobject.md)
- [getCapacity](kernel/osset/1808152-getcapacity.md)
- [getCapacityIncrement](kernel/osset/1808173-getcapacityincrement.md)
- [getCount](kernel/osset/1808189-getcount.md)
- [initWithArray](kernel/osset/1808200-initwitharray.md)
- [initWithCapacity](kernel/osset/1808213-initwithcapacity.md)
- [initWithObjects](kernel/osset/1808221-initwithobjects.md)
- [initWithSet](kernel/osset/1808228-initwithset.md)
- [isEqualTo(const OSMetaClassBase *)](kernel/osset/1808235-isequalto.md)
- [isEqualTo(const OSSet *)](kernel/osset/1808239-isequalto.md)
- [member](kernel/osset/1808245-member.md)
- [merge(const OSArray *)](kernel/osset/1808250-merge.md)
- [merge(const OSSet *)](kernel/osset/1808253-merge.md)
- [removeObject](kernel/osset/1808257-removeobject.md)
- [serialize](kernel/osset/1808260-serialize.md)
- [setCapacityIncrement](kernel/osset/1808264-setcapacityincrement.md)
- [withArray](kernel/osset/1808277-witharray.md)
- [withCapacity](kernel/osset/1808282-withcapacity.md)
- [withObjects](kernel/osset/1808287-withobjects.md)
- [withSet](kernel/osset/1808291-withset.md)
