Inherits from NSManagedObject
Declared in MMRecord.h
MMRecord.m

Overview

MMRecord provides a pattern for interfacing with a server to retrieve records. A record is an object that lives on a server. MMRecord depends on the interface from MMServer for making requests of various types. MMRecord also inherits from NSManagedObject and it is assumed that each type of record also corresponds to a certain type of Entity in a managed object model.

Configuration – Primary Keys

You must configure your Core Data model correctly for MMRecord to work effectively. There are two main parts to consider in configuring your data model. The first is that all record types should have a primary key identified by the MMRecordEntityPrimaryAttributeKey key in the Entity’s userInfo dictionary. This will be used to uniquely identify records in the event of an update. Typically this will be an integer or a string attribute.

Configuration – Primary Key Relationships

The primary key property can also be a relationship. The way the relationship primary key works is by establishing the existence of the parent relationship. In order to do that, the root parent relationship must have a primary key itself in order to be fetchable from Core Data. If the root parent object exists, then MMRecord will traverse the relationships of that existing object to see if the child which we are trying to uniquely identify exists, and if so it will update that object rather than create a duplicate entry in the database. While this is supported for to-many relationships, it is INTENDED for to-one relationships. It’s much easier to reliably identify a unique to-one relationship than a to-many relationship. As such, while to-many relationships are supported, they are ONLY supported if the fields in the Entity directly map to the fields in the response object. If you cannot depend on these fields matching exactly then you should look for ways to refactor the API or your data model, possibly through the use of value transformers or keyPaths.

Configuration – Alternate Name Keys

You can also configure your data model through the use of altername attribute name keys. There is more information on their use above, but these are generally used when the name of an object’s key in the response changes, or when the name is undesirable to use, such as if it is restricted by Core Data, or includes underscores.

Configuration – NSValueTransformers

MMRecord will also respect the NSValueTransformer subclass defined on a transformable attribute. If a value transformer is set on an attribute description, then MMRecord will use that transformer to transform the value for that attribute. If no value transformer is set, then NSKeyedArchiver will be used.

Configuration – Parsing and Population

The parsing and population system of MMRecord can be configured to handle special cases as well. The entry point for customizing this system is the MMRecordRepresentation class, and corresponding MMRecordMarshaler class – which is defined by the representation. You can declare a custom representation on a subclass of MMRecord. For more information about custom representations and marshalers please see those corresponding header files.

Configuration – Dates

The parsing and population can support dates in either date format string form, or unix time stamp number form. If the date from your request is a unix time stamp that is returned in the form of a number, then the date attribute will be populated with a date created from that unix time stamp. No action is required by you.If the value returned is a date format string, then you must override the dateFormatter method in your MMRecord subclass to provide a dateFormatter that can parse that given date format string. That formatter will then be used to populate date attributes for that class of record.

Server

You must create your own version of MMServer that implements the methods in it’s interface. Your server class must make a request and call the response/failure blocks with a response object or error. You must also associate a MMServer subclass with MMRecord or your base subclass of MMRecord that all of your individual records inherit from.

Requests

Each MMRecord subclass has access to methods to start a request. The most basic version of these methods simply takes a URN, data, a context, and a result/failure block. There are other methods for initiating a paged request, and for asking an instance of a record to obtain it’s detail object from the server. All of these methods handle the parsing of the response for you. They use data contained in the object model to know how to create record instances from the response. This is explained in more detail below.

Subclassing Notes

You must create a subclass of MMRecord for every entity in your data model that you wish to support this pattern. There is only one method that you must override: keyPathForResponseObject. One strategy for subclassing is to implement this method, and dateFormatter, in a base subclass for common API responses. You may override additional methods such as recordWithDictionary if you need to, but the idea is that you shouldn’t have to. You should override recordDetailURN if you wish to support detail requests.

Methods to Override

To allow date attribute parsing you must override the dateFormatter method and return a date formatter configured for your server’s date format. To support detail requests you must override recordDetailURN.

Object Construction

Everything needed to populate your records should be defined in your Managed Object Model. By default MMRecord will iterate through the record’s entity’s properties and look for response items with matching names. You can customize the names it searches for using various keys in the entity’s UserInfo dictionary. This method works just as well for relationships and transformable attributes as for normal attributes. If an entity’s inverse relationship entity is also of type MMRecord then instances of that record will be created for a relationship property. Transformable attributes will be created by using the NSValueTransformer class specified in the data model.

Custom Requests

The intended use of this class is that you will create methods on your own record subclasses such as +tweetsForUser: which will call super’s startRequestWithURN method and pass through a context, resultBlock and failureBlock parameters to super. The only parameters that would be determined inside of tweetsForUser would be the request URN and the data parameters required to make that request. This accomplishes the goal of encapsulating request-making logic inside of the data model in a way where it only needs to be defined once for an entire project, as well as taking advantage of the data parsing functionality of MMRecord so that every server call doesn’t need to roll it’s own parsing code.

Custom Request Handlers

You may wish to create and use request methods that include more information than just the generated objects that are supplied by the request’s response. Support for this is supplied through the Custom Request Handler block, which is a block passed into an advanced version of the -startRequestWithURN: method. This block will be called with the full response object in a decoded JSON form to allow you to glean additional information and return it in the form of an object. This works best with data which is not intended to be stored in the database. That object will then be passed to the actual resultBlock for you to use there as well. As a best practice, I recommend creating a custom NSObject subclass to encapsulate whatever piece of information you intend on taking from that response and passing on to the resultBlock. One example of where this may be useful is for driving a list request. You may need to be able to tell how many objects are in the list even if you only received back a few of them. If the request has that information in the meta, or somewhere else, then grab it out, put it in an object and return it. The total result count isn’t something you need stored access to, because it’s really only relevant in that one UI use-case. As such it’s a perfect candidate for this type of system. Another example is MMServerPageManager support. There’s a category on MMRecord for supporting pagination which includes a method called -startPagedRequestWithURN: that uses a Custom Request Handler in it’s implementation. Please look at that as a starting point for implementing this functionality for yourself.

Caching

In general, the best way to implement caching is through the use of NSURLCache and the server’s implementation of the HTTP Cache Control headers. In the event that this is not enough, MMRecord does provide an additional level of caching support. The caching provided by MMRecord is in accordance with the cache control headers and augments the system provided by NSURLCache. If caching is enabled then MMRecord will store the object IDs for each request/response pair that were parsed as part of the last response in a separate SQLite persistent store. It’s important to note that these are stored UNENCRYPTED. IF DATA SECURITY IS A REQUIREMENT CACHING SHOULD NOT BE USED! The methods required to support caching are listed below in the optional subclass methods. The primary one is isRecordLevelCachingEnabled, which should return YES if caching is desired. In addition, the optional method +requestWithURN:data: on MMServer must be implemented as a NSURLRequest object is required for accessing information in NSURLCache.

Queues

All MMRecord resultBlocks and failureBlocks are called on the Main Queue. Support for specific callback queues will be added in a future version.

This extenion to MMRecord enables the user to set various options to customize the behavior of a specific MMRecord request.

This category adds support for running a fetch request alongside the URL request. It is meant for when data is likely to exist in some form, stale or otherwise, in the persistent store and it would be useful to return the existing data as quickly as possible and then follow up soon thereafter with the latest data from a web service.

This category adds improved support for custom handling of pagination within requests. It uses the customResponseBlock functionality documented above to achieve this goal, and is intended both as a great tool for implementing paginated HTTP requests, as well as a reference implementation for how to use the customResponseBlock feature.

Tasks

Required Subclass Methods

  • + keyPathForResponseObject

    Must return the key path where records are located within the response object. This will only be called if your response object is of type dictionary.

Optional Subclass Methods

  • + shouldUseSubEntityRecordClassToRepresentData:

    This method can be implemented to determine if a sub entity record class should be used to represent the data for a particular record. The dictionary representation of the record is passed as a parameter, and the implementation should return YES or NO if that dictionary is a valid representation for a record of this type. This method is NOT intended to be used for validation, but for population when a record class has sub entities associated with it’s entity description. The typical use case would be for when you are requesting records of a given class, but depending on the response values, some (or all) of the records contained in the response should result in a sub entity record type being created or updated.

  • + representationClass

    This method should be used when a user of this class would like to use a different representation class for populating instances of this record class.

  • – recordDetailURN

    This method is used by the -startDetailRequestWithDomain: method to locate and obtain the resource data for a specific record. This URN should be everything after the base URL that is necesary to provide a unique location for obtaining the specified resource. A common implementation of this method will be to return a resource URI obtained via a previous server call. For APIs that do not support this you will need to construct this URN yourself.

  • + dateFormatter

    This method is used by all of the parsing method base implementations to obtain a date formatter configured for handling the server’s specified date format.

  • + isRecordLevelCachingEnabled

    This method indicates whether records returned are cacheable. The record level cache is keyed by the request URL and will obey the HTTP cache control headers.

  • + keyPathForMetaData

    This method returns the key path where metadata for the records are located within the response object. This will only be called if your response object is of type dictionary. Returning a non-nil value will short-circuit parsing the cached response body and build a subset of the response using this key and the value from the actual response. This method is provided purely for performance considerations and is not required.

Setting and Accessing the MMServer Class

Configuring the Output and Error Logging Level

  • + setLoggingLevel:

    Set the desired logging level for internal warning, error, and debug log statements. Messages are logged when certain events take place, such as parsing errors, missing data warnings, and improperly configured data models.

  • + loggingLevel

    Access the set logging level for internal warning, error, and debug log statements.

Starting and Stopping Server Requests

Other Methods

  • + setOptions:

    This method allows you to set a specific set of options for a single MMRecord request. MMRecordOptions follows the design paradigm set forth in Core Animation with the notion of an implicit transaction. Every MMRecord request starts with a default set of options. The defaults are specified above in the options class. Options are intended to be used sparingly and in special circumstances. As such, a set of options will only be applied to the first request started after -setOptions: is called. If you want those options to be used for every request, or for a specific request every time it’s called, you should encapsulate that request inside of another method which sets a new set of options before starting the request on MMRecord.

  • + defaultOptions

    Designated accessor for obtaining the default set of options for a given class of MMRecord.

MMRecordFetchRequests Methods

  • + startRequestWithURN:data:context:domain:fetchRequest:customResponseBlock:resultBlock:failureBlock:

    Starts a dual fetch and web request to retrieve information as quickly and as efficiently as possible. This method IS MEANT to be wrapped in a subclass’s implementation which hides the fetch request, URN, etc. from the caller. The caller (presumably a view controller) should not need to know about how to build the fetch request, it should only care about the data being received in the result block.

MMServerPageManager Methods

  • + startPagedRequestWithURN:data:context:domain:resultBlock:failureBlock:

    Starts a paged request on the registered server class. This is achieved by passing YES as the paging parameter. The server class is responsible for handling this accordingly, if paging functionality is desired. The purpose of this method is to enable the caller to receive a first page for a given resource and to subsequently request further pages. The signature of the result block is therefore changed to account for this functionality.

Class Methods

cancelRequestsWithDomain:

Calls the registered server class’s cancel requests method.

+ (void)cancelRequestsWithDomain:(id)domain

Parameters

domain

The domain value for which requests should be cancelled.

Discussion

Calls the registered server class’s cancel requests method.

Declared In

MMRecord.h

dateFormatter

This method is used by all of the parsing method base implementations to obtain a date formatter configured for handling the server’s specified date format.

+ (NSDateFormatter *)dateFormatter

Return Value

A NSDateFormatter configured to handle the server’s date format. @discussion You do not have to implement this method if your request returns unix date time stamps as numbers.

Discussion

This method is used by all of the parsing method base implementations to obtain a date formatter configured for handling the server’s specified date format.

Warning: If you do not implement this method and attempt to populate properties of type Date with a string value you will receive a parsing error.

Warning: You should store the date formatter you create as a static variable so that it’s not recreated by every request. Don’t be surprised if this functionality is changed later so that the user isn’t responsible for handling this.

Declared In

MMRecord.h

defaultOptions

Designated accessor for obtaining the default set of options for a given class of MMRecord.

+ (MMRecordOptions *)defaultOptions

Discussion

Designated accessor for obtaining the default set of options for a given class of MMRecord.

Declared In

MMRecord.h

isRecordLevelCachingEnabled

This method indicates whether records returned are cacheable. The record level cache is keyed by the request URL and will obey the HTTP cache control headers.

+ (BOOL)isRecordLevelCachingEnabled

Discussion

This method indicates whether records returned are cacheable. The record level cache is keyed by the request URL and will obey the HTTP cache control headers.

Declared In

MMRecord.h

keyPathForMetaData

This method returns the key path where metadata for the records are located within the response object. This will only be called if your response object is of type dictionary. Returning a non-nil value will short-circuit parsing the cached response body and build a subset of the response using this key and the value from the actual response. This method is provided purely for performance considerations and is not required.

+ (NSString *)keyPathForMetaData

Discussion

This method returns the key path where metadata for the records are located within the response object. This will only be called if your response object is of type dictionary. Returning a non-nil value will short-circuit parsing the cached response body and build a subset of the response using this key and the value from the actual response. This method is provided purely for performance considerations and is not required.

Declared In

MMRecord.h

keyPathForResponseObject

Must return the key path where records are located within the response object. This will only be called if your response object is of type dictionary.

+ (NSString *)keyPathForResponseObject

Discussion

Must return the key path where records are located within the response object. This will only be called if your response object is of type dictionary.

Declared In

MMRecord.h

loggingLevel

Access the set logging level for internal warning, error, and debug log statements.

+ (MMRecordLoggingLevel)loggingLevel

Discussion

Access the set logging level for internal warning, error, and debug log statements.

Warning: The loggingLevel is stored but ignored when Cocoa Lumberjack is being used.

Declared In

MMRecord.h

registerServerClass:

Register a server class with MMRecord. This will be the class used for starting all requests from MMRecord.

+ (BOOL)registerServerClass:(Class)server

Parameters

server

A class to be used for making requests. Must be a subclass of MMServer.

Return Value

Yes if registration was successful, NO otherwise. @discussion Pass nil to unregister a previously registered server.

Discussion

Register a server class with MMRecord. This will be the class used for starting all requests from MMRecord.

Warning: Must be a subclass of MMServer.

Declared In

MMRecord.h

representationClass

This method should be used when a user of this class would like to use a different representation class for populating instances of this record class.

+ (Class)representationClass

Return Value

The MMRecordRepresentation subclass you would like to use for this type of record. @discussion The default representation class is MMRecordRepresentation. See it’s header for more details.

Discussion

This method should be used when a user of this class would like to use a different representation class for populating instances of this record class.

Declared In

MMRecord.h

server

Access to the registered server class.

+ (Class)server

Return Value

The server class that has been registered with MMRecord.

Discussion

Access to the registered server class.

Declared In

MMRecord.h

setLoggingLevel:

Set the desired logging level for internal warning, error, and debug log statements. Messages are logged when certain events take place, such as parsing errors, missing data warnings, and improperly configured data models.

+ (void)setLoggingLevel:(MMRecordLoggingLevel)loggingLevel

Parameters

loggingLevel

The desired logging level

Discussion

Set the desired logging level for internal warning, error, and debug log statements. Messages are logged when certain events take place, such as parsing errors, missing data warnings, and improperly configured data models.

Warning: The loggingLevel is ignored when Cocoa Lumberjack is being used.

Declared In

MMRecord.h

setOptions:

This method allows you to set a specific set of options for a single MMRecord request. MMRecordOptions follows the design paradigm set forth in Core Animation with the notion of an implicit transaction. Every MMRecord request starts with a default set of options. The defaults are specified above in the options class. Options are intended to be used sparingly and in special circumstances. As such, a set of options will only be applied to the first request started after -setOptions: is called. If you want those options to be used for every request, or for a specific request every time it’s called, you should encapsulate that request inside of another method which sets a new set of options before starting the request on MMRecord.

+ (void)setOptions:(MMRecordOptions *)options

Parameters

options

The options object to be set on MMRecord.

Discussion

This method allows you to set a specific set of options for a single MMRecord request. MMRecordOptions follows the design paradigm set forth in Core Animation with the notion of an implicit transaction. Every MMRecord request starts with a default set of options. The defaults are specified above in the options class. Options are intended to be used sparingly and in special circumstances. As such, a set of options will only be applied to the first request started after -setOptions: is called. If you want those options to be used for every request, or for a specific request every time it’s called, you should encapsulate that request inside of another method which sets a new set of options before starting the request on MMRecord.

Warning: Options are implicitly reset after a request is run @discussion Tip: if you want multiple requests to use a specific set of options, you can group them in a batch block and they will all use the specified options that you set before starting the batch request.

Declared In

MMRecord.h

shouldUseSubEntityRecordClassToRepresentData:

This method can be implemented to determine if a sub entity record class should be used to represent the data for a particular record. The dictionary representation of the record is passed as a parameter, and the implementation should return YES or NO if that dictionary is a valid representation for a record of this type. This method is NOT intended to be used for validation, but for population when a record class has sub entities associated with it’s entity description. The typical use case would be for when you are requesting records of a given class, but depending on the response values, some (or all) of the records contained in the response should result in a sub entity record type being created or updated.

+ (BOOL)shouldUseSubEntityRecordClassToRepresentData:(NSDictionary *)dict

Parameters

dict

The dictionary representation of a record.

Return Value

YES if the dictionary represents a record of this type, NO otherwise. @discussion This method will be called when startRequestForURN is called on a MMRecord class whose entity description contains sub entities. This method will be called on each of those in no particular order and will use the class for the first record class that returns YES. If no record classes return YES, the called MMRecord class will be used.

Discussion

This method can be implemented to determine if a sub entity record class should be used to represent the data for a particular record. The dictionary representation of the record is passed as a parameter, and the implementation should return YES or NO if that dictionary is a valid representation for a record of this type. This method is NOT intended to be used for validation, but for population when a record class has sub entities associated with it’s entity description. The typical use case would be for when you are requesting records of a given class, but depending on the response values, some (or all) of the records contained in the response should result in a sub entity record type being created or updated.

Declared In

MMRecord.h

startBatchedRequestsInExecutionBlock:withCompletionBlock:

Starts batched requests.

+ (void)startBatchedRequestsInExecutionBlock:(void ( ^ ) ( ))batchExecutionBlock withCompletionBlock:(void ( ^ ) ( ))completionBlock

Parameters

batchExecutionBlock

A block in which all batched requests should be started. This block will be executed immediately and all requests started inside of it will be associated with the same dispatch group and started with the batched property set to YES.

completionBlock

A block to be executed when the dispatch group notify occurs signaling that the group has finished executing.

Discussion

Starts batched requests.

Declared In

MMRecord.h

startPagedRequestWithURN:data:context:domain:resultBlock:failureBlock:

Starts a paged request on the registered server class. This is achieved by passing YES as the paging parameter. The server class is responsible for handling this accordingly, if paging functionality is desired. The purpose of this method is to enable the caller to receive a first page for a given resource and to subsequently request further pages. The signature of the result block is therefore changed to account for this functionality.

+ (void)startPagedRequestWithURN:(NSString *)URN data:(NSDictionary *)parameters context:(NSManagedObjectContext *)context domain:(id)domain resultBlock:(void ( ^ ) ( NSArray *records , id pageManager , BOOL *requestNextPage ))resultBlock failureBlock:(void ( ^ ) ( NSError *error ))failureBlock

Parameters

URN

The base URN for the request endpoint.

parameters

A dictionary containing request parameters.

context

The managed object context that will be used for creating the records that are returned in the response.

domain

The domain that this request should be associated with.

resultBlock

A block object to be executed when the request finishes successfully. Before the block is called the response will be parsed and records will be created. An instance of the MMServerPageManager class designated by MMRecord’s registered server is also initialized. This class should be a subclass for your specific server that is implemented to handle that server’s paging functionality. The page manager object will know the URN for the next and previous pages. The block is called with the records and page manager object as parameters. There is also a reference to a boolean for requestNextPage. This is defaulted to NO. If the block changes this parameter to YES then a subsequent request will be started to retrieve the next page. The subsequent request will use the original result and failure blocks to handle it’s response.

failureBlock

A block object to be executed when the request finishes unsuccessfully. The block contains an error object that describes a request failure or a record parsing failure.

Discussion

Starts a paged request on the registered server class. This is achieved by passing YES as the paging parameter. The server class is responsible for handling this accordingly, if paging functionality is desired. The purpose of this method is to enable the caller to receive a first page for a given resource and to subsequently request further pages. The signature of the result block is therefore changed to account for this functionality.

Declared In

MMRecord.h

startRequestWithURN:data:context:domain:customResponseBlock:resultBlock:failureBlock:

Starts a request on the registered server class. This is an advanced implementation of this method with additional functionality.

+ (void)startRequestWithURN:(NSString *)URN data:(NSDictionary *)parameters context:(NSManagedObjectContext *)context domain:(id)domain customResponseBlock:(id ( ^ ) ( id JSON ))customResponseBlock resultBlock:(void ( ^ ) ( NSArray *records , id customResponseObject ))resultBlock failureBlock:(void ( ^ ) ( NSError *error ))failureBlock

Parameters

URN

The base URN for the request endpoint.

parameters

A dictionary containing request parameters.

context

The managed object context that will be used for creating the records that are returned in the response.

domain

The domain that this request should be associated with.

customResponseBlock

This block allows the user raw access to the parsed response from the request. Users can then extract other information from the response, such as meta information, result totals and indexes, etc. The user is expected to store that information in an object and have this block return that object. That object will then be passed as a parameter to the result block, giving the user access to that information. If this block returns nil, customResponseObject will be nil in the result block.

resultBlock

A block object to be executed when the request finishes successfully. Before the block is called the response will be parsed and records will be created. The block is called with those records as a parameter. Before this block is called the customResponseBlock will be called, and the second parameter will be the return of that block. If the customResponseBlock is nil, the customResponseObject parameter will be nil.

failureBlock

A block object to be executed when the request finishes unsuccessfully. The block contains an error object that describes a request failure or a record parsing failure.

Discussion

Starts a request on the registered server class. This is an advanced implementation of this method with additional functionality.

Declared In

MMRecord.h

startRequestWithURN:data:context:domain:fetchRequest:customResponseBlock:resultBlock:failureBlock:

Starts a dual fetch and web request to retrieve information as quickly and as efficiently as possible. This method IS MEANT to be wrapped in a subclass’s implementation which hides the fetch request, URN, etc. from the caller. The caller (presumably a view controller) should not need to know about how to build the fetch request, it should only care about the data being received in the result block.

+ (void)startRequestWithURN:(NSString *)URN data:(NSDictionary *)parameters context:(NSManagedObjectContext *)context domain:(id)domain fetchRequest:(NSFetchRequest *)fetchRequest customResponseBlock:(id ( ^ ) ( id JSON ))customResponseBlock resultBlock:(void ( ^ ) ( NSArray *records , id customResponseObject , BOOL requestComplete ))resultBlock failureBlock:(void ( ^ ) ( NSError *error ))failureBlock

Parameters

URN

The base URN for the request endpoint.

parameters

A dictionary containing request parameters.

context

The managed object context that will be used for creating the records that are returned in the response.

domain

The domain that this request should be associated with.

fetchRequest

An NSFetchRequest configured to fetch data of the same type as the request is meant to receive from Core Data.

customResponseBlock

This block allows the user raw access to the parsed response from the request. Users can then extract other information from the response, such as meta information, result totals and indexes, etc. The user is expected to store that information in an object and have this block return that object. That object will then be passed as a parameter to the result block, giving the user access to that information. If this block returns nil, customResponseObject will be nil in the result block.

resultBlock

A block object to be executed when the request finishes successfully. Before the block is called the response will be parsed and records will be created. The block is called with those records as a parameter. Before this block is called the customResponseBlock will be called, and the second parameter will be the return of that block. If the customResponseBlock is nil, the customResponseObject parameter will be nil.

failureBlock

A block object to be executed when the request finishes unsuccessfully. The block contains an error object that describes a request failure or a record parsing failure.

Discussion

Starts a dual fetch and web request to retrieve information as quickly and as efficiently as possible. This method IS MEANT to be wrapped in a subclass’s implementation which hides the fetch request, URN, etc. from the caller. The caller (presumably a view controller) should not need to know about how to build the fetch request, it should only care about the data being received in the result block.

Declared In

MMRecord.h

startRequestWithURN:data:context:domain:resultBlock:failureBlock:

Starts a request on the registered server class. This is the default implementation of this method.

+ (void)startRequestWithURN:(NSString *)URN data:(NSDictionary *)parameters context:(NSManagedObjectContext *)context domain:(id)domain resultBlock:(void ( ^ ) ( NSArray *records ))resultBlock failureBlock:(void ( ^ ) ( NSError *error ))failureBlock

Parameters

URN

The base URN for the request endpoint.

parameters

A dictionary containing request parameters.

context

The managed object context that will be used for creating the records that are returned in the response.

domain

The domain that this request should be associated with.

resultBlock

A block object to be executed when the request finishes successfully. Before the block is called the response will be parsed and records will be created. The block is called with those records as a parameter.

failureBlock

A block object to be executed when the request finishes unsuccessfully. The block contains an error object that describes a request failure or a record parsing failure.

Discussion

Starts a request on the registered server class. This is the default implementation of this method.

Declared In

MMRecord.h

Instance Methods

recordDetailURN

This method is used by the -startDetailRequestWithDomain: method to locate and obtain the resource data for a specific record. This URN should be everything after the base URL that is necesary to provide a unique location for obtaining the specified resource. A common implementation of this method will be to return a resource URI obtained via a previous server call. For APIs that do not support this you will need to construct this URN yourself.

- (NSString *)recordDetailURN

Return Value

A NSString containing the detail URN for the record.

Discussion

This method is used by the -startDetailRequestWithDomain: method to locate and obtain the resource data for a specific record. This URN should be everything after the base URL that is necesary to provide a unique location for obtaining the specified resource. A common implementation of this method will be to return a resource URI obtained via a previous server call. For APIs that do not support this you will need to construct this URN yourself.

Warning: If you do not implement this method then the startDetailRequest method will implicitly fail.

Declared In

MMRecord.h

startDetailRequestWithDomain:resultBlock:failureBlock:

Starts a detail request for an instance of a record. This method calls the recordDetailURN method, which should be implemented by a record needing to use this method. The record detail URN will be used as the location for fetching the detail resource for the record.

- (void)startDetailRequestWithDomain:(id)domain resultBlock:(void ( ^ ) ( MMRecord *record ))resultBlock failureBlock:(void ( ^ ) ( NSError *error ))failureBlock

Parameters

domain

The domain that this request should be associated with.

resultBlock

A block object to be executed when the request finishes successfully. The block contains a reference to the calling record which will have been updated with the returned data from the detail request.

failureBlock

A block object to be executed when the request finishes unsuccessfully. The block contains an error object that describes a request failure or a record parsing failure.

Discussion

Starts a detail request for an instance of a record. This method calls the recordDetailURN method, which should be implemented by a record needing to use this method. The record detail URN will be used as the location for fetching the detail resource for the record.

Declared In

MMRecord.h