MockNetworkDataManager
open class MockNetworkDataManager: NSObject
Allows an application developer to provide mock data responses for URLSession and other types of network request classes (UIWebView for example).
The MockNetworkDataManager works with mock data providers to determine if a requested URL should return real network data or mock network data.
By default the MockNetworkDataManager uses a default data provider that works with a resource bundle and plist to determine if a requested URL should return mock data. Here is an example of how the default provider works:
In a project define a MockData.bundle resource bundle, inside that bundle it should contain all of the contents you need to mock a network response for a request. The bundle should also include a DataMapping.plist file.
Example:
<?xml version=1.0
encoding=UTF-8
?>
<!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd
>
Alternatively you can define a simple response structure, this will return the response for ANY requests sent for the given endpoint
<?xml version=1.0
encoding=UTF-8
?>
<!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd
>
The data is loaded from disk as raw Data using the contents of file as the data response. This means the default provider should be able to work with most file types (JSON, text, images, video, etc.)
-
When enabled requests that do not have mocked data associated with them will be sent as regular network requests.
Declaration
Swift
public static var nonMockedURLsShouldSendNetworkRequests = true
-
Enables the ability return mock data for network requests. default: false
Declaration
Swift
public static var allowMockDataGlobally = false