---
title: WebDataSource
framework: webkit
role: symbol
role_heading: Class
path: webkit/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:) WebView class method.

## Declaration

```swift
class WebDataSource
```

## Overview

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 before accessing its data. Use data to get the raw data. Use the representation method to get the actual representation object and query it for more details.

## Topics

### Initializing an instance

- [init(request:)](webkit/webdatasource/init(request:).md)

### Querying page data and state

- [data](webkit/webdatasource/data.md)
- [isLoading](webkit/webdatasource/isloading.md)
- [pageTitle](webkit/webdatasource/pagetitle.md)
- [representation](webkit/webdatasource/representation.md)
- [textEncodingName](webkit/webdatasource/textencodingname.md)

### Getting the request and response

- [initialRequest](webkit/webdatasource/initialrequest.md)
- [request](webkit/webdatasource/request.md)
- [response](webkit/webdatasource/response.md)

### Getting the web frame

- [webFrame](webkit/webdatasource/webframe.md)

### Getting an unreachable URL

- [unreachableURL](webkit/webdatasource/unreachableurl.md)

### Getting a web archive

- [webArchive](webkit/webdatasource/webarchive.md)

### Accessing subresources

- [mainResource](webkit/webdatasource/mainresource.md)
- [addSubresource(_:)](webkit/webdatasource/addsubresource(_:).md)
- [subresource(for:)](webkit/webdatasource/subresource(for:).md)
- [subresources](webkit/webdatasource/subresources.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Working with Frames (Legacy)

- [WebFrame](webkit/webframe.md)
- [WebFrameView](webkit/webframeview.md)
- [WebFrameLoadDelegate](webkit/webframeloaddelegate.md)
