---
title: withString
framework: Kernel
role: symbol
role_heading: Type Method
platforms: [driverkit 19.0+, macOS 10.15+]
path: kernel/osstring/3180979-withstring
---

# withString

Allocates an OSString object with a copy of an OString object.

## Declaration

```occ
static OSStringPtr withString(const OSString *aString);
```

```occ
static OSPtr<OSString> withString(const OSString *aString);
```

## Parameters

- `aString`: OSString object to copy from. The string will be copied at the time of the call.

## Return Value

Return Value NULL on failure, otherwise the allocated OSString with reference count 1 to be released by the caller.

## Discussion

Discussion Allocates an OSString object with a copy of an OString object.

## See Also

### Creating a String

- [withCString](kernel/osstring/3180977-withcstring.md)
- [withCString](kernel/osstring/3433854-withcstring.md)
- [withCStringNoCopy](kernel/osstring/3180978-withcstringnocopy.md)
- [free](kernel/osstring/3180973-free.md)
