Iglistkit: Question about a property declaration in IGListSectionMap

Created on 19 Jan 2017  路  4Comments  路  Source: Instagram/IGListKit

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.

bug starter-task

All 4 comments

@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.

let's get this in 2.2

@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

Closed by #436

Was this page helpful?
0 / 5 - 0 ratings

Related issues

racer1988 picture racer1988  路  3Comments

lucabartoletti picture lucabartoletti  路  3Comments

shuhrat10 picture shuhrat10  路  3Comments

Przemyslaw-Wosko picture Przemyslaw-Wosko  路  3Comments

kleiberjp picture kleiberjp  路  3Comments