Просмотр исходного кода

Fix #426

Move explicit FLEXCollection protocol conformances to the .m file to prevent protocol methods from overriding the methods in their headers
Tanner Bennett лет назад: 5
Родитель
Сommit
e79a3db255

+ 6 - 14
Classes/ObjectExplorers/Sections/FLEXCollectionContentSection.h

@@ -11,7 +11,11 @@
 @class FLEXCollectionContentSection, FLEXTableViewCell;
 @protocol FLEXCollection, FLEXMutableCollection;
 
-typedef id<FLEXCollection>(^FLEXCollectionContentFuture)(__kindof FLEXCollectionContentSection *section);
+/// Any foundation collection implicitly conforms to FLEXCollection.
+/// This future should return one. We don't explicitly put FLEXCollection
+/// here because making generic collections conform to FLEXCollection breaks
+/// compile-time features of generic arrays, such as \c someArray[0].property
+typedef id<NSObject, NSFastEnumeration /* FLEXCollection */>(^FLEXCollectionContentFuture)(__kindof FLEXCollectionContentSection *section);
 
 #pragma mark Collection
 /// A protocol that enables \c FLEXCollectionContentSection to operate on any arbitrary collection.
@@ -41,18 +45,6 @@ typedef id<FLEXCollection>(^FLEXCollectionContentFuture)(__kindof FLEXCollection
 - (void)filterUsingPredicate:(NSPredicate *)predicate;
 @end
 
-@interface NSArray (FLEXCollection) <FLEXCollection> @end
-@interface NSSet (FLEXCollection) <FLEXCollection> @end
-@interface NSOrderedSet (FLEXCollection) <FLEXCollection> @end
-@interface NSDictionary (FLEXCollection) <FLEXCollection> @end
-
-@interface NSMutableArray (FLEXMutableCollection) <FLEXMutableCollection> @end
-@interface NSMutableSet (FLEXMutableCollection) <FLEXMutableCollection> @end
-@interface NSMutableOrderedSet (FLEXMutableCollection) <FLEXMutableCollection> @end
-@interface NSMutableDictionary (FLEXMutableCollection) <FLEXMutableCollection>
-- (void)filterUsingPredicate:(NSPredicate *)predicate;
-@end
-
 
 #pragma mark - FLEXCollectionContentSection
 /// A custom section for viewing collection elements.
@@ -68,7 +60,7 @@ typedef id<FLEXCollection>(^FLEXCollectionContentFuture)(__kindof FLEXCollection
     id<FLEXCollection> _cachedCollection;
 }
 
-+ (instancetype)forCollection:(id<FLEXCollection>)collection;
++ (instancetype)forCollection:(id)collection;
 /// The future given should be safe to call more than once.
 /// The result of calling this future multiple times may yield
 /// different results each time if the data is changing by nature.

+ 14 - 3
Classes/ObjectExplorers/Sections/FLEXCollectionContentSection.m

@@ -21,6 +21,17 @@ typedef NS_ENUM(NSUInteger, FLEXCollectionType) {
     FLEXKeyedCollection
 };
 
+@interface NSArray (FLEXCollection) <FLEXCollection> @end
+@interface NSSet (FLEXCollection) <FLEXCollection> @end
+@interface NSOrderedSet (FLEXCollection) <FLEXCollection> @end
+@interface NSDictionary (FLEXCollection) <FLEXCollection> @end
+
+@interface NSMutableArray (FLEXMutableCollection) <FLEXMutableCollection> @end
+@interface NSMutableSet (FLEXMutableCollection) <FLEXMutableCollection> @end
+@interface NSMutableOrderedSet (FLEXMutableCollection) <FLEXMutableCollection> @end
+@interface NSMutableDictionary (FLEXMutableCollection) <FLEXMutableCollection>
+- (void)filterUsingPredicate:(NSPredicate *)predicate;
+@end
 
 @interface FLEXCollectionContentSection ()
 /// Generated from \c collectionFuture or \c collection
@@ -54,7 +65,7 @@ typedef NS_ENUM(NSUInteger, FLEXCollectionType) {
 + (id)forReusableFuture:(FLEXCollectionContentFuture)collectionFuture {
     FLEXCollectionContentSection *section = [self new];
     section->_collectionFuture = collectionFuture;
-    section.cachedCollection = collectionFuture(section);
+    section.cachedCollection = (id<FLEXCollection>)collectionFuture(section);
     section->_collectionType = [self typeForCollection:section.cachedCollection];
     section->_isMutable = [section->_cachedCollection respondsToSelector:@selector(filterUsingPredicate:)];
     return section;
@@ -180,13 +191,13 @@ typedef NS_ENUM(NSUInteger, FLEXCollectionType) {
         [tmp filterUsingPredicate:filter];
         self.cachedCollection = tmp;
     } else {
-        self.cachedCollection = self.collection ?: self.collectionFuture(self);
+        self.cachedCollection = self.collection ?: (id<FLEXCollection>)self.collectionFuture(self);
     }
 }
 
 - (void)reloadData {
     if (self.collectionFuture) {
-        self.cachedCollection = self.collectionFuture(self);
+        self.cachedCollection = (id<FLEXCollection>)self.collectionFuture(self);
     } else {
         self.cachedCollection = self.collection.copy;
     }

+ 1 - 1
Classes/ObjectExplorers/Sections/FLEXMutableListSection.m

@@ -47,7 +47,7 @@ configurationBlock:(FLEXMutableListCellForElement)cellConfig
 
 - (void)setList:(NSMutableArray *)list {
     NSParameterAssert(list);
-    _collection = list;
+    _collection = (id)list;
 
     [self reloadData];
 }