Skip to content

Instantly share code, notes, and snippets.

@kean
kean / gist:ae2b051225208ec4d871
Created March 2, 2015 10:18
DFImageActivityItemProvider draft
@interface DFImageActivityItemProvider : UIActivityItemProvider
- (instancetype)initWithPlaceholderItem:(id)placeholderItem request:(DFImageRequest *)request;
@end
@implementation DFImageActivityItemProvider {
DFImageRequest *_request;
DFImageRequestID *_requestID;
}
@kean
kean / DFCompositeImageTask
Last active September 11, 2015 08:23
Compose DFImageTask objects
// DFCompositeImageTask.h
#import "DFImageManagerDefines.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class DFCompositeImageTask;
@class DFImageRequest;
@class DFImageTask;
@protocol DFImageManaging;
@kean
kean / DFProxyImageManager
Created September 11, 2015 08:23
Extend DFImageManaging API
// DFProxyImageManager.h
#import "DFImageManaging.h"
#import "DFImageRequest.h"
#import <Foundation/Foundation.h>
/*! The DFProxyRequestTransforming protocol defines an interface for transforming application-specific classes or protocols to the resources supported by the DFImageManager.
*/
@protocol DFProxyRequestTransforming <NSObject>
@kean
kean / gist:511d247fad4d6f76254a
Created November 17, 2015 09:58
UIViewController Keyboard Management
@interface ViewController : UIViewController
@property (nonatomic, readonly, nullable) UIView *keyboardAnchorView;
@property (nonatomic, readonly, nullable) NSLayoutConstraint *keyboardAnchorViewHeightConstraint;
@end
@implementation
@import DFImageManager;
@interface CustomImageLoadingView
- (void)prepareForReuse;
- (void)setImageWithRequest:(nonnull DFImageRequest *)request;
@end
@implementation CustomImageLoadingView {
// The MIT License (MIT)
//
// Copyright (c) 2015 Alexander Grebenyuk (github.com/kean).
import XCTest
import Foundation
extension XCTestCase {
public func expect(block: (fulfill: (Void) -> Void) -> Void) {
let expectation = self.expectation()
var request = ImageRequest(URLRequest: <#NSURLRequest#>)
request.targetSize = CGSize(width: 200, height: 200) // Resize image
request.processor = <#ImageProcessing#> // Apply image filters
Nuke.taskWithRequest(request) { response in
let image = response.image
}.resume()
- (void)_fetchSomethingOrDieWithCompletion:(void (^)(id something))completion {
_autoRetryController = [[[GMURLAutoRetryController alloc] initWithBlock:^(GMAutoRetryController * _Nonnull controller) {
[/* start request with */ completion:^(id __nullable something, NSError * __nullable error) {
if (error) {
[controller scheduleAutoRetryWithError:error];
} else {
completion(something);
}
}];
}] resume];
#import "GMAutoRetryController.h"
#import "NSTimer+GMBlocks.h"
#import "NSError+Fitmeup.h"
#import "GMNetworkReachability.h"
#import "GMRepository.h"
typedef NS_ENUM(NSInteger, _GMARCState) {
_GMARCStateSuspended, // initial state
#import <Foundation/Foundation.h>
static const NSInteger GMAutoRetryControllerInfiniteAttemptCount = INT_MAX;
/*! Auto retry with progressive delay. Thread safe.
*/
@interface GMAutoRetryController : NSObject
@property (nullable, nonatomic, copy) void (^block)(GMAutoRetryController *__nonnull autoRetryController);