iOS Developer Library

Developer

Foundation Framework Reference NSCachedURLResponse Class Reference

Options
Deployment Target:

On This Page
Language:

NSCachedURLResponse

Inherits From


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 2.0 and later

An NSCachedURLResponse object represents a cached response to a URL request. It provides the server’s response metadata in the form of an NSURLResponse object, along with an NSData object containing the actual cached content data. Its storage policy determines whether the response should be cached on disk, in memory, or not at all.

Cached responses also contain a user info dictionary where you can store app-specific information about the cached item.

The NSURLCache class stores and retrieves instances of NSCachedURLResponse.

  • Initializes an NSCachedURLResponse object.

    Declaration

    Swift

    init(response response: NSURLResponse, data data: NSData)

    Objective-C

    - (instancetype)initWithResponse:(NSURLResponse *)response data:(NSData *)data

    Parameters

    response

    The response to cache.

    data

    The data to cache.

    Return Value

    The NSCachedURLResponse object, initialized using the given data.

    Discussion

    The cache storage policy is set to the default, NSURLCacheStorageAllowed, and the user info dictionary is set to nil.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

  • Initializes an NSCachedURLResponse object.

    Declaration

    Swift

    init(response response: NSURLResponse, data data: NSData, userInfo userInfo: [NSObject : AnyObject]?, storagePolicy storagePolicy: NSURLCacheStoragePolicy)

    Objective-C

    - (instancetype)initWithResponse:(NSURLResponse *)response data:(NSData *)data userInfo:(NSDictionary *)userInfo storagePolicy:(NSURLCacheStoragePolicy)storagePolicy

    Parameters

    response

    The response to cache.

    data

    The data to cache.

    userInfo

    An optional dictionary of user information. May be nil.

    storagePolicy

    The storage policy for the cached response.

    Return Value

    The NSCachedURLResponse object, initialized using the given data.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

  • data data Property

    The receiver’s cached data. (read-only)

    Declaration

    Swift

    @NSCopying var data: NSData { get }

    Objective-C

    @property(readonly, copy) NSData *data

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

  • response response Property

    The URL response object associated with the receiver. (read-only)

    Declaration

    Swift

    @NSCopying var response: NSURLResponse { get }

    Objective-C

    @property(readonly, copy) NSURLResponse *response

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

  • The receiver’s cache storage policy. (read-only)

    Declaration

    Swift

    var storagePolicy: NSURLCacheStoragePolicy { get }

    Objective-C

    @property(readonly) NSURLCacheStoragePolicy storagePolicy

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

  • userInfo userInfo Property

    The receiver’s user info dictionary. (read-only)

    Declaration

    Swift

    var userInfo: [NSObject : AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSDictionary *userInfo

    Discussion

    nil if there is no user info dictionary.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

Data Types

  • These constants specify the caching strategy used by an NSCachedURLResponse object.

    Declaration

    Swift

    enum NSURLCacheStoragePolicy : UInt { case Allowed case AllowedInMemoryOnly case NotAllowed }

    Objective-C

    typedef enum { NSURLCacheStorageAllowed, NSURLCacheStorageAllowedInMemoryOnly, NSURLCacheStorageNotAllowed, } NSURLCacheStoragePolicy;

    Constants

    • Allowed

      NSURLCacheStorageAllowed

      Specifies that storage in NSURLCache is allowed without restriction.

      Available in iOS 2.0 and later

    • AllowedInMemoryOnly

      NSURLCacheStorageAllowedInMemoryOnly

      Specifies that storage in NSURLCache is allowed; however storage should be restricted to memory only.

      Available in iOS 2.0 and later

    • NotAllowed

      NSURLCacheStorageNotAllowed

      Specifies that storage in NSURLCache is not allowed in any fashion, either in memory or on disk.

      Available in iOS 2.0 and later

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later