---
title: "CFBridgingRetain(_:)"
framework: foundation
role: symbol
role_heading: Function
path: "foundation/cfbridgingretain(_:)"
---

# CFBridgingRetain(_:)

Casts an Objective-C pointer to a Core Foundation pointer and also transfers ownership to the caller.

## Declaration

```swift
func CFBridgingRetain(_ X: Any?) -> CFTypeRef?
```

## Discussion

Discussion You use this function to cast an Objective-C object as Core Foundation-style object and take ownership of the object so that you can manage its lifetime. You are responsible for subsequently releasing the object, as illustrated in this example: NSString *string = <#Get a string#>; CFStringRef cfString = (CFStringRef)CFBridgingRetain(string); // Use the CF string. CFRelease(cfString);
