FLEXCollectionContentSection.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "FLEXTableViewSection.h"
  9. #import "FLEXObjectInfoSection.h"
  10. @class FLEXCollectionContentSection, FLEXTableViewCell;
  11. @protocol FLEXCollection, FLEXMutableCollection;
  12. typedef id<FLEXCollection>(^FLEXCollectionContentFuture)(__kindof FLEXCollectionContentSection *section);
  13. #pragma mark Collection
  14. /// A protocol that enables \c FLEXCollectionContentSection to operate on any arbitrary collection.
  15. /// \c NSArray, \c NSDictionary, \c NSSet, and \c NSOrderedSet all conform to this protocol.
  16. @protocol FLEXCollection <NSObject, NSFastEnumeration>
  17. @property (nonatomic, readonly) NSUInteger count;
  18. - (id<FLEXCollection>)copy;
  19. - (id<FLEXMutableCollection>)mutableCopy;
  20. @optional
  21. /// Unordered, unkeyed collections must implement this
  22. @property (nonatomic, readonly) NSArray *allObjects;
  23. /// Keyed collections must implement this and \c objectForKeyedSubscript:
  24. @property (nonatomic, readonly) NSArray *allKeys;
  25. /// Ordered, indexed collections must implement this.
  26. - (id)objectAtIndexedSubscript:(NSUInteger)idx;
  27. /// Keyed, unordered collections must implement this and \c allKeys
  28. - (id)objectForKeyedSubscript:(id)idx;
  29. @end
  30. @protocol FLEXMutableCollection <FLEXCollection>
  31. - (void)filterUsingPredicate:(NSPredicate *)predicate;
  32. @end
  33. @interface NSArray (FLEXCollection) <FLEXCollection> @end
  34. @interface NSSet (FLEXCollection) <FLEXCollection> @end
  35. @interface NSOrderedSet (FLEXCollection) <FLEXCollection> @end
  36. @interface NSDictionary (FLEXCollection) <FLEXCollection> @end
  37. @interface NSMutableArray (FLEXMutableCollection) <FLEXMutableCollection> @end
  38. @interface NSMutableSet (FLEXMutableCollection) <FLEXMutableCollection> @end
  39. @interface NSMutableOrderedSet (FLEXMutableCollection) <FLEXMutableCollection> @end
  40. @interface NSMutableDictionary (FLEXMutableCollection) <FLEXMutableCollection>
  41. - (void)filterUsingPredicate:(NSPredicate *)predicate;
  42. @end
  43. #pragma mark - FLEXCollectionContentSection
  44. /// A custom section for viewing collection elements.
  45. ///
  46. /// Tapping on a row pushes an object explorer for that element.
  47. @interface FLEXCollectionContentSection<__covariant ObjectType> : FLEXTableViewSection <FLEXObjectInfoSection>
  48. + (instancetype)forCollection:(id<FLEXCollection>)collection;
  49. /// The future given should be safe to call more than once.
  50. /// The result of calling this future multiple times may yield
  51. /// different results each time if the data is changing by nature.
  52. + (instancetype)forReusableFuture:(FLEXCollectionContentFuture)collectionFuture;
  53. /// Defaults to \c NO
  54. @property (nonatomic) BOOL hideSectionTitle;
  55. /// Defaults to \c nil
  56. @property (nonatomic) NSString *customTitle;
  57. /// Defaults to \c NO
  58. ///
  59. /// Settings this to \c NO will not display the element index for ordered collections.
  60. /// This property only applies to \c NSArray or \c NSOrderedSet and their subclasses.
  61. @property (nonatomic) BOOL hideOrderIndexes;
  62. /// Set this property to provide a custom filter matcher.
  63. ///
  64. /// By default, the collection will filter on the title and subtitle of the row.
  65. /// So if you don't ever call \c configureCell: for example, you will need to set
  66. /// this property so that your filter logic will match how you're setting up the cell.
  67. @property (nonatomic) BOOL (^customFilter)(NSString *filterText, ObjectType element);
  68. /// Get the object in the collection associated with the given row.
  69. /// For dictionaries, this returns the value, not the key.
  70. - (ObjectType)objectForRow:(NSInteger)row;
  71. @end