---
title: "CFURLCreateData(_:_:_:_:)"
framework: corefoundation
role: symbol
role_heading: Function
path: "corefoundation/cfurlcreatedata(_:_:_:_:)"
---

# CFURLCreateData(_:_:_:_:)

Creates a CFData object containing the content of a given URL.

## Declaration

```swift
func CFURLCreateData(_ allocator: CFAllocator!, _ url: CFURL!, _ encoding: CFStringEncoding, _ escapeWhitespace: Bool) -> CFData!
```

## Parameters

- `allocator`: The allocator to use to allocate memory for the new CFData object. Pass NULL or doc://com.apple.corefoundation/documentation/CoreFoundation/kCFAllocatorDefault to use the current default allocator.
- `url`: The URL to convert into a CFData object.
- `encoding`: The string encoding to use when converting url into a CFData object.
- `escapeWhitespace`: true if you want to escape whitespace characters in the URL, false otherwise.

## Return Value

Return Value A new CFData object containing the content of url. Ownership follows the create rule. See The Create Rule.

## Discussion

Discussion This function escapes any character that is not 7-bit ASCII with the byte-code for the given encoding. If escapeWhitespace is true, whitespace characters (’ ’, ‘\t’, ‘\r’, ‘\n’) will be escaped as well. This is desirable if you want to embed the URL into a larger text stream like HTML.

## See Also

### Converting URLs to Other Representations

- [CFURLCreateStringByAddingPercentEscapes(_:_:_:_:_:)](corefoundation/cfurlcreatestringbyaddingpercentescapes(_:_:_:_:_:).md)
- [CFURLCreateStringByReplacingPercentEscapes(_:_:_:)](corefoundation/cfurlcreatestringbyreplacingpercentescapes(_:_:_:).md)
- [CFURLCreateStringByReplacingPercentEscapesUsingEncoding(_:_:_:_:)](corefoundation/cfurlcreatestringbyreplacingpercentescapesusingencoding(_:_:_:_:).md)
- [CFURLGetFileSystemRepresentation(_:_:_:_:)](corefoundation/cfurlgetfilesystemrepresentation(_:_:_:_:).md)
- [CFURLGetFSRef(_:_:)](corefoundation/cfurlgetfsref(_:_:).md)
- [CFURLGetString(_:)](corefoundation/cfurlgetstring(_:).md)
