FLEXCollectionContentSection.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // FLEXCollectionContentSection.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/28/19.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXTableViewSection.h"
  9. #import "FLEXObjectInfoSection.h"
  10. @class FLEXCollectionContentSection, FLEXTableViewCell;
  11. @protocol FLEXCollection, FLEXMutableCollection;
  12. /// Any foundation collection implicitly conforms to FLEXCollection.
  13. /// This future should return one. We don't explicitly put FLEXCollection
  14. /// here because making generic collections conform to FLEXCollection breaks
  15. /// compile-time features of generic arrays, such as \c someArray[0].property
  16. typedef id<NSObject, NSFastEnumeration /* FLEXCollection */>(^FLEXCollectionContentFuture)(__kindof FLEXCollectionContentSection *section);
  17. #pragma mark Collection
  18. /// A protocol that enables \c FLEXCollectionContentSection to operate on any arbitrary collection.
  19. /// \c NSArray, \c NSDictionary, \c NSSet, and \c NSOrderedSet all conform to this protocol.
  20. @protocol FLEXCollection <NSObject, NSFastEnumeration>
  21. @property (nonatomic, readonly) NSUInteger count;
  22. - (id)copy;
  23. - (id)mutableCopy;
  24. @optional
  25. /// Unordered, unkeyed collections must implement this
  26. @property (nonatomic, readonly) NSArray *allObjects;
  27. /// Keyed collections must implement this and \c objectForKeyedSubscript:
  28. @property (nonatomic, readonly) NSArray *allKeys;
  29. /// Ordered, indexed collections must implement this.
  30. - (id)objectAtIndexedSubscript:(NSUInteger)idx;
  31. /// Keyed, unordered collections must implement this and \c allKeys
  32. - (id)objectForKeyedSubscript:(id)idx;
  33. @end
  34. @protocol FLEXMutableCollection <FLEXCollection>
  35. - (void)filterUsingPredicate:(NSPredicate *)predicate;
  36. @end
  37. #pragma mark - FLEXCollectionContentSection
  38. /// A custom section for viewing collection elements.
  39. ///
  40. /// Tapping on a row pushes an object explorer for that element.
  41. @interface FLEXCollectionContentSection<__covariant ObjectType> : FLEXTableViewSection <FLEXObjectInfoSection> {
  42. @protected
  43. /// Unused if initialized with a future
  44. id<FLEXCollection> _collection;
  45. /// Unused if initialized with a collection
  46. FLEXCollectionContentFuture _collectionFuture;
  47. /// The filtered collection from \c _collection or \c _collectionFuture
  48. id<FLEXCollection> _cachedCollection;
  49. }
  50. + (instancetype)forCollection:(id)collection;
  51. /// The future given should be safe to call more than once.
  52. /// The result of calling this future multiple times may yield
  53. /// different results each time if the data is changing by nature.
  54. + (instancetype)forReusableFuture:(FLEXCollectionContentFuture)collectionFuture;
  55. /// Defaults to \c NO
  56. @property (nonatomic) BOOL hideSectionTitle;
  57. /// Defaults to \c nil
  58. @property (nonatomic, copy) NSString *customTitle;
  59. /// Defaults to \c NO
  60. ///
  61. /// Settings this to \c NO will not display the element index for ordered collections.
  62. /// This property only applies to \c NSArray or \c NSOrderedSet and their subclasses.
  63. @property (nonatomic) BOOL hideOrderIndexes;
  64. /// Set this property to provide a custom filter matcher.
  65. ///
  66. /// By default, the collection will filter on the title and subtitle of the row.
  67. /// So if you don't ever call \c configureCell: for example, you will need to set
  68. /// this property so that your filter logic will match how you're setting up the cell.
  69. @property (nonatomic) BOOL (^customFilter)(NSString *filterText, ObjectType element);
  70. /// Get the object in the collection associated with the given row.
  71. /// For dictionaries, this returns the value, not the key.
  72. - (ObjectType)objectForRow:(NSInteger)row;
  73. /// Subclasses may override.
  74. - (UITableViewCellAccessoryType)accessoryTypeForRow:(NSInteger)row;
  75. @end