<!--
{
  "availability" : [
    "macOS: 10.3.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebDataSource",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WebDataSource"
  },
  "title" : "WebDataSource"
}
-->

# WebDataSource

`WebDataSource` encapsulates the web content to be displayed in a web frame view. A `WebDataSource` object has a representation object, conforming to the `WebDocumentRepresentation` protocol, that holds the data in an appropriate format depending on the MIME type. You can extend WebKit to support new MIME types by implementing your own view and representation classes, and specifying the mapping between them using the  [`registerClass(_:representationClass:forMIMEType:)`](/documentation/WebKit/WebView-swift.class/registerClass(_:representationClass:forMIMEType:)) `WebView` class method.

```
class WebDataSource
```

## Overview

`WebDataSource` objects have an associated initial request, possibly a modified request, and a response object. Since the data source may be in the process of being loaded, you should check the state of a data source using [`isLoading`](/documentation/WebKit/WebDataSource/isLoading) before accessing its data. Use [`data`](/documentation/WebKit/WebDataSource/data) to get the raw data. Use the [`representation`](/documentation/WebKit/WebDataSource/representation) method to get the actual representation object and query it for more details.

## Topics

### Initializing an instance

[`-  initWithRequest:`](/documentation/WebKit/WebDataSource/init(request:))

initializes a data source with a URL request.

### Querying page data and state

[`data`](/documentation/WebKit/WebDataSource/data)

The raw data that represents the data source’s content.

[`loading`](/documentation/WebKit/WebDataSource/isLoading)

A Boolean that indicates whether the data source is loading its content.

[`pageTitle`](/documentation/WebKit/WebDataSource/pageTitle)

The title of the data source’s page.

[`representation`](/documentation/WebKit/WebDataSource/representation)

The data source’s representation depending on its MIME type.

[`textEncodingName`](/documentation/WebKit/WebDataSource/textEncodingName)

The text encoding for the data source’s web view, if set, or the text encoding of the response.

### Getting the request and response

[`initialRequest`](/documentation/WebKit/WebDataSource/initialRequest)

A reference to the original request that was used to load the web content.

[`request`](/documentation/WebKit/WebDataSource/request)

The request that was used to create the data source.

[`response`](/documentation/WebKit/WebDataSource/response)

The response for this data source.

### Getting the web frame

[`webFrame`](/documentation/WebKit/WebDataSource/webFrame)

The web frame that represents this data source.

### Getting an unreachable URL

[`unreachableURL`](/documentation/WebKit/WebDataSource/unreachableURL)

The data source’s unreachable URL.

### Getting a web archive

[`webArchive`](/documentation/WebKit/WebDataSource/webArchive)

A web archive representing the data source, its subresources, and subframes.

### Accessing subresources

[`mainResource`](/documentation/WebKit/WebDataSource/mainResource)

A`WebResource` object representing the data source.

[`-  addSubresource:`](/documentation/WebKit/WebDataSource/addSubresource(_:))

Adds a resource to the data source’s list of subresources.

[`-  subresourceForURL:`](/documentation/WebKit/WebDataSource/subresource(for:))

Returns a subresource for the given URL.

[`subresources`](/documentation/WebKit/WebDataSource/subresources)

The data source’s subresources that have finished downloading.

## Relationships

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)