SDWebImageCompat.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. * (c) Jamie Pinkham
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. #import <TargetConditionals.h>
  10. #ifdef __OBJC_GC__
  11. #error SDWebImage does not support Objective-C Garbage Collection
  12. #endif
  13. // Apple's defines from TargetConditionals.h are a bit weird.
  14. // Seems like TARGET_OS_MAC is always defined (on all platforms).
  15. // To determine if we are running on OSX, we can only rely on TARGET_OS_IPHONE=0 and all the other platforms
  16. #if !TARGET_OS_IPHONE && !TARGET_OS_IOS && !TARGET_OS_TV && !TARGET_OS_WATCH
  17. #define SD_MAC 1
  18. #else
  19. #define SD_MAC 0
  20. #endif
  21. // iOS and tvOS are very similar, UIKit exists on both platforms
  22. // Note: watchOS also has UIKit, but it's very limited
  23. #if TARGET_OS_IOS || TARGET_OS_TV
  24. #define SD_UIKIT 1
  25. #else
  26. #define SD_UIKIT 0
  27. #endif
  28. #if TARGET_OS_IOS
  29. #define SD_IOS 1
  30. #else
  31. #define SD_IOS 0
  32. #endif
  33. #if TARGET_OS_TV
  34. #define SD_TV 1
  35. #else
  36. #define SD_TV 0
  37. #endif
  38. #if TARGET_OS_WATCH
  39. #define SD_WATCH 1
  40. #else
  41. #define SD_WATCH 0
  42. #endif
  43. #if SD_MAC
  44. #import <AppKit/AppKit.h>
  45. #ifndef UIImage
  46. #define UIImage NSImage
  47. #endif
  48. #ifndef UIImageView
  49. #define UIImageView NSImageView
  50. #endif
  51. #ifndef UIView
  52. #define UIView NSView
  53. #endif
  54. #else
  55. #if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
  56. #error SDWebImage doesn't support Deployment Target version < 5.0
  57. #endif
  58. #if SD_UIKIT
  59. #import <UIKit/UIKit.h>
  60. #endif
  61. #if SD_WATCH
  62. #import <WatchKit/WatchKit.h>
  63. #ifndef UIView
  64. #define UIView WKInterfaceObject
  65. #endif
  66. #ifndef UIImageView
  67. #define UIImageView WKInterfaceImage
  68. #endif
  69. #endif
  70. #endif
  71. #ifndef NS_ENUM
  72. #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
  73. #endif
  74. #ifndef NS_OPTIONS
  75. #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
  76. #endif
  77. FOUNDATION_EXPORT UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
  78. typedef void(^SDWebImageNoParamsBlock)(void);
  79. FOUNDATION_EXPORT NSString *const SDWebImageErrorDomain;
  80. #ifndef dispatch_queue_async_safe
  81. #define dispatch_queue_async_safe(queue, block)\
  82. if (dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL) == dispatch_queue_get_label(queue)) {\
  83. block();\
  84. } else {\
  85. dispatch_async(queue, block);\
  86. }
  87. #endif
  88. #ifndef dispatch_main_async_safe
  89. #define dispatch_main_async_safe(block) dispatch_queue_async_safe(dispatch_get_main_queue(), block)
  90. #endif