<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLResponse/init(url:mimeType:expectedContentLength:textEncodingName:)-4s2s1",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLResponse(im)initWithURL:MIMEType:expectedContentLength:textEncodingName:"
  },
  "title" : "init(url:mimeType:expectedContentLength:textEncodingName:)"
}
-->

# init(url:mimeType:expectedContentLength:textEncodingName:)

Creates an initialized [`URLResponse`](/documentation/Foundation/URLResponse) object with the URL, MIME type, length, and text encoding set to given values.

```
init(url URL: URL, mimeType MIMEType: String?, expectedContentLength length: Int, textEncodingName name: String?)
```

## Parameters

`URL`

The URL for the new object.

`MIMEType`

The MIME type.

`length`

The expected content length.This value should be `–1` if the expected length is undetermined

`name`

The text encoding name. This value may be `nil`.

## Return Value

The initialized URL response.

## Discussion

This is the designated initializer for [`URLResponse`](/documentation/Foundation/URLResponse).

## See Also

[`-  initWithURL:statusCode:HTTPVersion:headerFields:`](/documentation/Foundation/HTTPURLResponse/init(url:statusCode:httpVersion:headerFields:)-21j4x)

Initializes an HTTP URL response object with a status code, protocol version, and response headers.



---

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)