<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFURLCreateWithBytes(_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFURLCreateWithBytes"
  },
  "title" : "CFURLCreateWithBytes(_:_:_:_:_:)"
}
-->

# CFURLCreateWithBytes(_:_:_:_:_:)

Creates a `CFURL` object using a given character bytes.

```
func CFURLCreateWithBytes(_ allocator: CFAllocator!, _ URLBytes: UnsafePointer<UInt8>!, _ length: CFIndex, _ encoding: CFStringEncoding, _ baseURL: CFURL!) -> CFURL!
```

## Parameters

`allocator`

The allocator to use to allocate memory for the new `CFURL` object. Pass `NULL` or [`kCFAllocatorDefault`](/documentation/CoreFoundation/kCFAllocatorDefault) to use the current default allocator.

`URLBytes`

The character bytes to convert into a `CFURL` object.

`length`

The number of bytes in `URLBytes`.

`encoding`

The string encoding of the `URLBytes` string. This encoding is also used to interpret percent escape sequences.

`baseURL`

The URL to which `URLBytes` is relative. Pass `NULL` if `URLBytes` contains an absolute URL or if you want to create a relative URL. If `URLBytes` contains an absolute URL, this parameter is ignored.

## Return Value

A new `CFURL` object. Ownership follows the create rule. See [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

The specified string encoding will be used both to interpret `URLBytes`, and to interpret any percent-escapes within the string.

> Note:
> This function does not support string encoding which isn’t a superset of ASCII encoding. Both ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFURLGetBytes(_:_:_:)`` and ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFURLGetByteRangeForComponent(_:_:_:)`` require 7-bit ASCII characters to be stored in a single 8-bit byte. The following ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStringEncodings`` can be used: ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStringBuiltInEncodings/macRoman``, ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStringBuiltInEncodings/windowsLatin1``, ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStringBuiltInEncodings/isoLatin1``, ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStringBuiltInEncodings/nextStepLatin``, ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStringBuiltInEncodings/ASCII`` and ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStringBuiltInEncodings/UTF8``.

---

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)