Mac Developer Library

Developer

WebKit Framework Reference WebDataSource Class Reference

Options
Deployment Target:

On This Page
Language:

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 registerViewClass:representationClass:forMIMEType: WebView class method.

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 loading 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.

  • initializes a data source with a URL request.

    Declaration

    Swift

    init!(request request: NSURLRequest!)

    Objective-C

    - (instancetype)initWithRequest:(NSURLRequest *)request

    Parameters

    request

    The URL request used to load the web content.

    Return Value

    The initialized web data source.

    Discussion

    This method is the designated initializer for WebDataSource objects. Normally, WebFrame objects create their data sources, so you should not invoke this method directly.

    Availability

    Available in OS X v10.2 and later.

  • data data Property

    The raw data that represents the data source’s content. (read-only)

    Declaration

    Swift

    @NSCopying var data: NSData! { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSData *data

    Discussion

    The format of the data is dependent on the data source’s MIME type (obtained from the response).

    Availability

    Available in OS X v10.2 and later.

  • A Boolean that indicates whether the data source is loading its content. (read-only)

    Declaration

    Swift

    var loading: Bool { get }

    Objective-C

    @property(nonatomic, getter=isLoading, readonly) BOOL loading

    Discussion

    YEStrue if the data source is in the process of loading its content; otherwise, NOfalse.

    Availability

    Available in OS X v10.10 and later.

  • The title of the data source’s page. (read-only)

    Declaration

    Swift

    var pageTitle: String! { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSString *pageTitle

    Discussion

    The associated web view notifies its frame load delegate when the page title is loaded by invoking the webView:didReceiveTitle:forFrame: delegate method.

    nil if the page has no title or the page title hasn’t been loaded yet.

    Availability

    Available in OS X v10.2 and later.

  • The data source’s representation depending on its MIME type. (read-only)

    Declaration

    Swift

    var representation: WebDocumentRepresentation! { get }

    Objective-C

    @property(nonatomic, readonly, strong) id< WebDocumentRepresentation > representation

    Discussion

    nil if the data source is in the process of being loaded and this method is invoked before loading is complete.

    You can specify the mapping between a representation and MIME type using the registerViewClass:representationClass:forMIMEType:WebView class method.

    Availability

    Available in OS X v10.2 and later.

  • The text encoding for the data source’s web view, if set, or the text encoding of the response. (read-only)

    Declaration

    Swift

    var textEncodingName: String! { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSString *textEncodingName

    Availability

    Available in OS X v10.2 and later.

  • The web frame that represents this data source. (read-only)

    Declaration

    Swift

    var webFrame: WebFrame! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebFrame *webFrame

    Availability

    Available in OS X v10.2 and later.

  • A web archive representing the data source, its subresources, and subframes. (read-only)

    Declaration

    Swift

    var webArchive: WebArchive! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebArchive *webArchive

    Discussion

    In the case of HTML, if the current content is preferred, then send webArchive to the appropriate DOM object.

    Availability

    Available in OS X v10.3 and later.

    See Also

    mainResource

  • AWebResource object representing the data source. (read-only)

    Declaration

    Swift

    var mainResource: WebResource! { get }

    Objective-C

    @property(nonatomic, readonly, strong) WebResource *mainResource

    Availability

    Available in OS X v10.3 and later.

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

    Declaration

    Swift

    func addSubresource(_ subresource: WebResource!)

    Objective-C

    - (void)addSubresource:(WebResource *)subresource

    Parameters

    subresource

    The resource to add to the data source.

    Discussion

    If the data source needs to reload the resource’s URL, it loads the data from subresource instead of the network. For example, use this method if you want to use a previously downloaded image rather than accessing the network to reload a resource. If the data source already has a resource with the same URL as subresource, then this method replaces it.

    Availability

    Available in OS X v10.3 and later.

  • Returns a subresource for the given URL.

    Declaration

    Swift

    func subresourceForURL(_ URL: NSURL!) -> WebResource!

    Objective-C

    - (WebResource *)subresourceForURL:(NSURL *)URL

    Parameters

    URL

    The subresource’s URL.

    Return Value

    The subresource for URL or nil if the data source hasn’t finished downloading the subresource.

    Availability

    Available in OS X v10.3 and later.

  • The data source’s subresources that have finished downloading. (read-only)

    Declaration

    Swift

    var subresources: [AnyObject]! { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSArray *subresources

    Availability

    Available in OS X v10.3 and later.