SDWebImageOptionsProcessor.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "SDWebImageOptionsProcessor.h"
  9. @interface SDWebImageOptionsResult ()
  10. @property (nonatomic, assign) SDWebImageOptions options;
  11. @property (nonatomic, copy, nullable) SDWebImageContext *context;
  12. @end
  13. @implementation SDWebImageOptionsResult
  14. - (instancetype)initWithOptions:(SDWebImageOptions)options context:(SDWebImageContext *)context {
  15. self = [super init];
  16. if (self) {
  17. self.options = options;
  18. self.context = context;
  19. }
  20. return self;
  21. }
  22. @end
  23. @interface SDWebImageOptionsProcessor ()
  24. @property (nonatomic, copy, nonnull) SDWebImageOptionsProcessorBlock block;
  25. @end
  26. @implementation SDWebImageOptionsProcessor
  27. - (instancetype)initWithBlock:(SDWebImageOptionsProcessorBlock)block {
  28. self = [super init];
  29. if (self) {
  30. self.block = block;
  31. }
  32. return self;
  33. }
  34. + (instancetype)optionsProcessorWithBlock:(SDWebImageOptionsProcessorBlock)block {
  35. SDWebImageOptionsProcessor *optionsProcessor = [[SDWebImageOptionsProcessor alloc] initWithBlock:block];
  36. return optionsProcessor;
  37. }
  38. - (SDWebImageOptionsResult *)processedResultForURL:(NSURL *)url options:(SDWebImageOptions)options context:(SDWebImageContext *)context {
  39. if (!self.block) {
  40. return nil;
  41. }
  42. return self.block(url, options, context);
  43. }
  44. @end