Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.87k stars 1.54k forks source link

Question about a property declaration in IGListSectionMap #433

Closed PhilCai1993 closed 7 years ago

PhilCai1993 commented 7 years ago

In IGListSectionMap.m there is a property sectionControllerToObjectMap.

@property (nonatomic, strong, readonly) NSMapTable<IGListSectionController<IGListSectionType> *, id> *sectionControllerToObjectMap;

After digging into it, I am wondering if it is better to be renamed objectToSectionControllerMap ? And the property should be declared as:

@property (nonatomic, strong, readonly) NSMapTable<id, IGListSectionController<IGListSectionType> *> *objectToSectionControllerMap;

According to this:

[self.sectionControllerToObjectMap setObject:sectionController forKey:object];

key is "object" and value is "sectionController"

And in iOS SDK, Foundation/NSMapTable, @interface NSMapTable<KeyType, ObjectType> : NSObject <NSCopying, NSCoding, NSFastEnumeration>

If this is a mistake, I'd love to create a pull request.

IGListKit has been used in our app to organize the code better.

Thanks.

rnystrom commented 7 years ago

@PhilCai1993 another great find. Yup this is a relic from refactors that happened over a year ago. Renaming would be great!

Looks like the compiler isn't complaining b/c the object is always id and the section controller values are generic id in the container.

jessesquires commented 7 years ago

let's get this in 2.2

PhilCai1993 commented 7 years ago

@rnystrom

I'm considering if it would be of benefit to make some parameter/return-type generic?

For example:

in IGListAdapter - (void)reloadObjects:(NSArray *)objects; ---> - (void)reloadObjects:(NSArray <id <IGListDiffable>>*)objects;

- (NSInteger)sectionForObject:(id)object; ---> - (NSInteger)sectionForObject:(id<IGListDiffable>)object;

In my opinion, when we are using those APIs, it's better if the compiler could give us a hint what the return-value/parameter should be.

For example, - (NSArray *)objects; in IGListAdapter is ambiguous at first sight.

But if it is -(NSArray<id <IGListDiffable>>)objects, I would guess it comes from - (NSArray<id <IGListDiffable>> *)objectsForListAdapter:(IGListAdapter *)listAdapter in IGListAdapterDataSource

Sherlouk commented 7 years ago

Closed by #436