FLEXCollectionContentSection.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // FLEXCollectionContentSection.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/28/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXExplorerSection.h"
  9. @class FLEXCollectionContentSection;
  10. @protocol FLEXCollection;
  11. typedef id<FLEXCollection>(^FLEXCollectionContentFuture)(__kindof FLEXCollectionContentSection *section);
  12. #pragma mark Collection
  13. /// A protocol that enables \c FLEXCollectionContentSection to operate on any arbitrary collection.
  14. /// \c NSArray, \c NSDictionary, \c NSSet, and \c NSOrderedSet all conform to this protocol.
  15. @protocol FLEXCollection <NSObject, NSFastEnumeration>
  16. @property (nonatomic, readonly) NSUInteger count;
  17. - (id)copy;
  18. - (id)mutableCopy;
  19. @optional
  20. /// Unordered, unkeyed collections must implement this
  21. @property (nonatomic, readonly) NSArray *allObjects;
  22. /// Keyed collections must implement this and \c objectForKeyedSubscript:
  23. @property (nonatomic, readonly) NSArray *allKeys;
  24. /// Ordered, indexed collections must implement this.
  25. - (id)objectAtIndexedSubscript:(NSUInteger)idx;
  26. /// Keyed, unordered collections must implement this and \c allKeys
  27. - (id)objectForKeyedSubscript:(id)idx;
  28. @end
  29. @interface NSArray (FLEXCollection) <FLEXCollection> @end
  30. @interface NSDictionary (FLEXCollection) <FLEXCollection> @end
  31. @interface NSSet (FLEXCollection) <FLEXCollection> @end
  32. @interface NSOrderedSet (FLEXCollection) <FLEXCollection> @end
  33. #pragma mark - FLEXCollectionContentSection
  34. /// A custom section for viewing collection elements.
  35. ///
  36. /// Tapping on a row pushes an object explorer for that element.
  37. @interface FLEXCollectionContentSection : FLEXExplorerSection <FLEXObjectInfoSection>
  38. + (instancetype)forCollection:(id<FLEXCollection>)collection;
  39. /// The future given should be safe to call more than once.
  40. /// The result of calling this future multiple times may yield
  41. /// different results each time if the data is changing by nature.
  42. + (instancetype)forReusableFuture:(FLEXCollectionContentFuture)collectionFuture;
  43. @end