CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

MUKContentFetch 1.3.3

MUKContentFetch 1.3.3

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Sep 2016

Maintained by Marco Muccinelli.



  • By
  • Marco Muccinelli

A simple infrastracture to retrieve requested data and transform it to content object.

Usage

Say you want to get and parse a JSON resource to show its entries inside a table view. You should isolate that fetch in a dedicated class not to pollute you view controller.

@interface DucksFetch : MUKContentFetch<NSArray<Duck *> *>
@end

@implementation DucksFetch

- (void)retrieveResourceWithCompletionHandler:(void (^)(MUKContentFetchStepResultType resultType, id retrievedObject, NSError *error))completionHandler
{
    dispatch_async(myQueue, ^{
        NSData *JSONData = ...;
        completionHandler(MUKContentFetchStepResultTypeSuccess, JSONData, nil);
    });
}

- (void)transformRetrievedObject:(id)retrievedObject withCompletionHandler:(void (^)(MUKContentFetchStepResultType resultType, id transformedObject, NSError *error))completionHandler
{
    dispatch_async(myQueue, ^{
        NSArray *ducks = ParseDucks(retrievedObject);
        completionHandler(MUKContentFetchStepResultTypeSuccess, ducks, nil);
    });
}

@end

To get data is now simple and clean.

DucksFetch *fetch = [[DucksFetch alloc] init];
[fetch startWithCompletionHandler:^(MUKContentFetchResponse *response) {
    self.ducks = response.object;
    [self updateUI];
}];

Obviously this is a small and incomplete example which does not mind about cancellation and error handling, two things you have (almost) for free using MUKContentFetch.

Requirements

  • iOS 7 SDK.
  • Minimum deployment target: iOS 7.

Author

Marco Muccinelli, [email protected]

License

MUKContentFetch is available under the MIT license. See the LICENSE file for more info.