<!--
{
  "availability" : [
    "iOS: 2.0.0 - 11.0.0",
    "iPadOS: 2.0.0 - 11.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.4.0 - 10.13.0",
    "tvOS: 9.0.0 - 11.0.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "CFNetwork",
  "identifier" : "/documentation/CFNetwork/CFNetDiagnosticCreateWithURL(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "CFNetwork"
    ],
    "preciseIdentifier" : "c:@F@CFNetDiagnosticCreateWithURL"
  },
  "title" : "CFNetDiagnosticCreateWithURL(_:_:)"
}
-->

# CFNetDiagnosticCreateWithURL(_:_:)

Creates a CFNetDiagnosticRef from a CFURLRef.

```
func CFNetDiagnosticCreateWithURL(_ alloc: CFAllocator, _ url: CFURL) -> Unmanaged<CFNetDiagnostic>
```

## Parameters

`alloc`

The allocator to use to allocate memory for the new object. Pass `NULL` or kCFAllocatorDefault to use the current default allocator.

`url`

CFURLRef that refers to the failed connection.

## Return Value

CFNetDiagnosticRef that you can pass to [`CFNetDiagnosticDiagnoseProblemInteractively(_:)`](/documentation/CFNetwork/CFNetDiagnosticDiagnoseProblemInteractively(_:)) or [`CFNetDiagnosticCopyNetworkStatusPassively(_:_:)`](/documentation/CFNetwork/CFNetDiagnosticCopyNetworkStatusPassively(_:_:)). Ownership follows the [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

This function uses a URL to create a reference to an instance of a CFNetDiagnostic object. You can pass the reference to [`CFNetDiagnosticDiagnoseProblemInteractively(_:)`](/documentation/CFNetwork/CFNetDiagnosticDiagnoseProblemInteractively(_:)) to open a Network Diagnostics window or to [`CFNetDiagnosticCopyNetworkStatusPassively(_:_:)`](/documentation/CFNetwork/CFNetDiagnosticCopyNetworkStatusPassively(_:_:)) to get a description of the connection referenced by `readStream` and `writeStream`.

### Special Considerations

This function is thread safe as long as another thread does not alter the same CFNetDiagnosticRef at the same time.

---

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)