Skip to content

Commit

Permalink
Update documentation; Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Sep 27, 2015
1 parent 43e6b73 commit 942fd9e
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 45 deletions.
5 changes: 3 additions & 2 deletions Pod/Source/Core/Managing/DFCompositeImageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#import "DFImageManaging.h"
#import <Foundation/Foundation.h>

/*! The DFCompositeImageManager is a dynamic dispatcher that constructs a chain of responsibility from multiple image manager. Each image manager added to the composite defines which image requests it can handle. The DFCompositeImageManager dispatches image requests starting with the first image manager in a chain. If the image manager can't handle the request it is passes to the next image manager in the chain and so on.
@note Composite image manager itself conforms to DFImageManaging protocol and can be added to other composite image managers, forming a tree structure.
/*! The DFCompositeImageManager is a dynamic dispatcher that constructs a tree of responsibility from multiple image managers and dynamically dispatch requests between them.
@note Each image manager defines which image requests it can handle. The DFCompositeImageManager dispatches image requests starting with the first image manager in a chain. If the image manager can't handle the request it is passes to the next image manager in the chain and so on.
@note The DFCompositeImageManager also conforms to DFImageManaging protocol so that individual managers and compositions can be treated uniformly.
*/
@interface DFCompositeImageManager : NSObject <DFImageManaging>

Expand Down
11 changes: 4 additions & 7 deletions Pod/Source/Core/Managing/DFCompositeImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ @implementation DFCompositeImageManager {
NSMutableArray<id<DFImageManaging>> *_managers;
}

- (nonnull instancetype)init {
if (self = [super init]) {
_managers = [NSMutableArray new];
}
return self;
}

- (nonnull instancetype)initWithImageManagers:(nonnull NSArray<id<DFImageManaging>> *)imageManagers {
if (self = [self init]) {
[_managers addObjectsFromArray:imageManagers];
}
return self;
}

- (nonnull instancetype)init {
return [self initWithImageManagers:@[]];
}

- (void)addImageManager:(nonnull id<DFImageManaging>)imageManager {
[_managers addObject:imageManager];
}
Expand Down
18 changes: 5 additions & 13 deletions Pod/Source/Core/Managing/DFImageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@

@class DFImageManagerConfiguration;

/*! The role of DFImageManager is to manage the execution of image tasks by delegating the actual job to the objects implementing DFImageFetching, DFImageCaching, DFImageDecoding, and DFImageProcessing protocols.
/*! The DFImageManager manages execution of image tasks by delegating the actual job to the objects conforming to DFImageFetching, DFImageCaching, DFImageDecoding, and DFImageProcessing protocols.
@note Reusing Operations
DFImageManager might use a single fetch operation for multiple image tasks with equivalent requests. Image manager cancels fetch operations only when there are no remaining image tasks registered with a given operation.
@note Memory Caching
DFImageManager uses DFImageCaching protocol for memory caching. It should be able to lookup cached images based on the image requests, but it doesn't know anything about the resources, specific request options, and the way the requests are interpreted and handled. There are three simple rules how image manager stores and retrieves cached images. First, image manager can't use cached images stored by other managers. Second, all resources must implement -hash method. Third, image manager uses special cache keys that delegate the test for equivalence of the image requests to the image fetcher (DFImageFetching) and the image processor (DFImageProcessing).
@note Preheating
DFImageManager does its best to guarantee that preheating tasks never interfere with regular (non-preheating) tasks. There is a limit of concurrent preheating tasks enforced by DFImageManager. There is also certain (very small) delay when manager starts executing preheating requests.
DFImageManager might uses a single fetch operation for image tasks with equivalent requests. Image manager cancels fetch operations only when there are no remaining image tasks registered with a given operation.
*/
@interface DFImageManager : NSObject <DFImageManaging>

/*! A copy of the configuration object for this manager (read only). Changing mutable values within the configuration object has no effect on the current manager.
/*! Returns a copy of the configuration object for this manager.
*/
@property (nonnull, nonatomic, copy, readonly) DFImageManagerConfiguration *configuration;

Expand All @@ -38,15 +30,15 @@
@end


/*! Dependency injectors for the image manager shared by the application.
/*! Dependency injectors.
*/
@interface DFImageManager (SharedManager)

/*! Returns the shared image manager instance.
*/
+ (nonnull id<DFImageManaging>)sharedManager;

/*! Sets the image manager instance shared by all clients of the current application.
/*! Sets the shared image manager.
*/
+ (void)setSharedManager:(nonnull id<DFImageManaging>)manager;

Expand Down
2 changes: 1 addition & 1 deletion Pod/Source/Core/Managing/DFImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ @implementation DFImageManager {
DF_INIT_UNAVAILABLE_IMPL

- (nonnull instancetype)initWithConfiguration:(nonnull DFImageManagerConfiguration *)configuration {
NSParameterAssert(configuration);
if (self = [super init]) {
NSParameterAssert(configuration);
_configuration = [configuration copy];
_imageLoader = [[DFImageManagerLoader alloc] initWithConfiguration:configuration];
_imageLoader.delegate = self;
Expand Down
4 changes: 2 additions & 2 deletions Pod/Source/Core/Managing/DFImageManagerConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ @implementation DFImageManagerConfiguration

DF_INIT_UNAVAILABLE_IMPL

- (nonnull instancetype)initWithFetcher:(nonnull id<DFImageFetching>)fetcher {
- (instancetype)initWithFetcher:(id<DFImageFetching>)fetcher {
NSParameterAssert(fetcher);
if (self = [super init]) {
_fetcher = fetcher;
Expand All @@ -23,7 +23,7 @@ - (nonnull instancetype)initWithFetcher:(nonnull id<DFImageFetching>)fetcher {
return self;
}

+ (nonnull instancetype)configurationWithFetcher:(nonnull id<DFImageFetching>)fetcher processor:(nullable id<DFImageProcessing>)processor cache:(nullable id<DFImageCaching>)cache {
+ (instancetype)configurationWithFetcher:(id<DFImageFetching>)fetcher processor:(id<DFImageProcessing>)processor cache:(id<DFImageCaching>)cache {
DFImageManagerConfiguration *conf = [[[self class] alloc] initWithFetcher:fetcher];
conf.processor = processor;
conf.cache = cache;
Expand Down
3 changes: 1 addition & 2 deletions Pod/Source/Core/Private/DFImageManagerLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ - (BOOL)isImageRequestKey:(nonnull _DFImageRequestKey *)lhs equalToKey:(nonnull

@end

/*! Make it possible to use DFImageRequest as a key in dictionaries (and dictionary-like structures). Requests are compared using -[DFImageFetching isRequestFetchEquivalent:toRequest:] method and -[DFImageProcessing isProcessingForRequestEquivalent:toRequest:] method (for cache and preheating)
/*! Make it possible to use DFImageRequest as a key in dictionaries, tables, etc. Requests are compared using -[DFImageFetching isRequestFetchEquivalent:toRequest:] and -[DFImageProcessing isProcessingForRequestEquivalent:toRequest:] methods.
*/
@interface _DFImageRequestKey : NSObject <NSCopying>

Expand Down Expand Up @@ -346,7 +346,6 @@ - (BOOL)_shouldProcessImage:(nonnull UIImage *)image forRequest:(nonnull DFImage
return [_conf.processor shouldProcessImage:image forRequest:request partial:partial];
}
return YES;
// return [_conf.processor shouldProcessImage:image forRequest:request partial:partial];
}

- (nullable DFCachedImageResponse *)cachedResponseForRequest:(nonnull DFImageRequest *)request {
Expand Down
3 changes: 3 additions & 0 deletions Pod/Source/Core/Processing/DFImageDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
/*! Image decoder that supports multiple image formats not supported by UIImage.
*/
@interface DFImageDecoder : NSObject <DFImageDecoding>

@end


/*! Composes image decoders.
*/
@interface DFCompositeImageDecoder : NSObject <DFImageDecoding>

/*! Initializes DFCompositeImageDecoder with an array of decoders.
*/
- (nonnull instancetype)initWithDecoders:(nonnull NSArray <id<DFImageDecoding>> *)decoders;

@end
1 change: 0 additions & 1 deletion Pod/Source/Core/Processing/DFImageDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Copyright (c) 2015 Alexander Grebenyuk (github.com/kean).

#import "DFImageDecoder.h"
#import "DFImageManagerDefines.h"

#if TARGET_OS_WATCH
#import <WatchKit/WatchKit.h>
Expand Down
4 changes: 0 additions & 4 deletions Pod/Source/Core/Support/DFImageManagerDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ typedef NS_ENUM(NSInteger, DFImageRequestPriority) {
DFImageRequestPriorityHigh
};

/*! Progress handler, called on a main thread.
*/
typedef void (^DFImageRequestProgressHandler)(double progress);

/*! The error domain for DFImageManager.
*/
extern NSString *__nonnull const DFImageManagerErrorDomain;
Expand Down
2 changes: 1 addition & 1 deletion Pod/Source/Core/Support/DFImageRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@class DFImageRequestOptions;

/*! The DFImageRequest class represents an image request for a specified resource. The request also contains options on how to retrieve and (optionally) process the image.
/*! The DFImageRequest class represents an image request for a specified resource.
*/
@interface DFImageRequest : NSObject

Expand Down
2 changes: 1 addition & 1 deletion Pod/Source/Core/Support/DFImageRequestOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@class DFMutableImageRequestOptions;

/*! You use a DFImageRequestOptions object to specify options when requesting image representations of resources using classes conforming DFImageManaging protocol.
/*! Use a DFImageRequestOptions object to specify options when requesting image representations of resources using classes conforming DFImageManaging protocol.
*/
@interface DFImageRequestOptions : NSObject

Expand Down
1 change: 1 addition & 0 deletions Pod/Source/GIF/DFAnimatedImageDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
#import "DFImageDecoding.h"

@interface DFAnimatedImageDecoder : NSObject <DFImageDecoding>

@end
6 changes: 6 additions & 0 deletions Pod/Source/GIF/DFAnimatedImageProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
*/
@interface DFAnimatedImageProcessor : NSObject <DFImageProcessing>

/*! Initialized animated image processor with an actual processor.
*/
- (nonnull instancetype)initWithProcessor:(nonnull id<DFImageProcessing>)processor;

/*! Unavailable initializer, please use designated initializer.
*/
- (nullable instancetype)init NS_UNAVAILABLE;

@end
5 changes: 4 additions & 1 deletion Pod/Source/GIF/DFAnimatedImageProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
//
// Copyright (c) 2015 Alexander Grebenyuk (github.com/kean).

#import "DFAnimatedImageProcessor.h"
#import "DFAnimatedImage.h"
#import "DFAnimatedImageProcessor.h"
#import "DFImageManagerDefines.h"

@implementation DFAnimatedImageProcessor {
id<DFImageProcessing> _processor;
}

DF_INIT_UNAVAILABLE_IMPL

- (instancetype)initWithProcessor:(id<DFImageProcessing>)processor {
if (self = [super init]) {
_processor = processor;
Expand Down
5 changes: 2 additions & 3 deletions Pod/Source/GIF/DFAnimatedImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#import "DFImageView.h"
#import <FLAnimatedImage/FLAnimatedImage.h>

/*! An image view extends UIImageView class with image fetching functionality. It also adds other features like managing request priorities and more.
@note The DFImageView uses FLAnimatedImageView to enable animated GIF playback. The playback is enabled by default and can be disabled using allowsGIFPlayback property. The DFImageView doesn't override any of the FLAnimatedImageView methods so should get the same experience as when using the FLAnimatedImageView class directly. The only addition is a new - (void)displayImage:(UIImage *)image method that supports DFAnimatedImage objects and will automatically start GIF playback when passed an object of that class.
/*! The DFAnimatedImageView uses FLAnimatedImageView to enable animated GIF playback.
@note The playback is enabled by default and can be disabled using allowsGIFPlayback property.
*/
@interface DFAnimatedImageView : DFImageView

Expand All @@ -19,7 +19,6 @@
@property (nonatomic) BOOL allowsGIFPlayback;

/*! Displays a given image. Automatically starts GIF playback when given a DFAnimatedImage object and when the GIF playback is enabled.
@note This method is always included in compilation even if the The 'GIF' subspec is not installed.
*/
- (void)displayImage:(nullable UIImage *)image;

Expand Down
2 changes: 1 addition & 1 deletion Pod/Source/PhotosKit/DFPhotosKitImageFetcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (instancetype)init {
return self;
}

#pragma mark - <DFImageFetching>
#pragma mark <DFImageFetching>

- (BOOL)canHandleRequest:(DFImageRequest *)request {
id asset = request.resource;
Expand Down
4 changes: 2 additions & 2 deletions Pod/Source/UI/DFImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@class DFImageRequest;
@class DFImageRequestOptions;

/*! An image view extends UIImageView class with image fetching functionality. It also adds other features like managing request priorities and more.
/*! The DFImageView extends UIImageView class with image fetching functionality. It also adds other features like managing request priorities and more.
*/
@interface DFImageView : UIImageView

Expand Down Expand Up @@ -44,7 +44,7 @@
*/
- (void)setImageWithRequest:(nullable DFImageRequest *)request;

/*! Method gets called when the completion block is called for the current image fetch task.
/*! Subclassing hook that gets called when the completion block is called for the current image fetch task.
*/
- (void)didCompleteImageTask:(nonnull DFImageTask *)task withImage:(nullable UIImage *)image;

Expand Down
2 changes: 1 addition & 1 deletion Pod/Source/UI/UIImageView+DFImageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@class DFImageRequest;
@class DFImageRequestOptions;

/*! Adds some very basic image fetching capabilities to the UIImageView. For more features see DFImageView.
/*! Adds some basic image fetching capabilities to the UIImageView. For more features see DFImageView.
*/
@interface UIImageView (DFImageManager)

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DFImageManager is a [pipeline](#h_design) that loads images using multiple depen
##### Loading
- Uses [NSURLSession](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSession_class/) with [HTTP/2](https://en.wikipedia.org/wiki/HTTP/2) support
- Optional [AFNetworking](#install_using_cocopods) integration, combine the power of both frameworks!
- Uses a single fetch operation for multiple equivalent requests
- Uses a single fetch operation for equivalent requests
- [Intelligent preheating](https://github.com/kean/DFImageManager/wiki/Image-Preheating-Guide) of images close to the viewport

##### Caching
Expand Down Expand Up @@ -177,12 +177,11 @@ configuration.cache = cache;
```
#### Composing Image Managers
The `DFCompositeImageManager` constructs a tree of responsibility from multiple image managers and dynamically dispatch requests between them. Each manager should conform to `DFImageManaging` protocol. The `DFCompositeImageManager` also conforms to `DFImageManaging` protocol which lets users to treat individual managers and compositions uniformly. For more info see [Composing Image Managers](https://github.com/kean/DFImageManager/wiki/Extending-Image-Manager-Guide#using-dfcompositeimagemanager).
The `DFCompositeImageManager` constructs a [tree of responsibility](https://github.com/kean/DFImageManager/wiki/Extending-Image-Manager-Guide#using-dfcompositeimagemanager) from image managers and dynamically dispatch requests between them. Each manager should conform to `DFImageManaging` protocol. The `DFCompositeImageManager` also conforms to `DFImageManaging` protocol so that individual managers and compositions can be treated uniformly.
```objective-c
id<DFImageManaging> manager1 = <#manager#>
id<DFImageManaging> manager2 = <#manager#>
id<DFImageManaging> composite = [[DFCompositeImageManager alloc] initWithImageManagers:@[manager1, manager2]];
```

Expand Down

0 comments on commit 942fd9e

Please sign in to comment.