Skip to content

Commit

Permalink
Swap NSUInteger to NSInteger Public API
Browse files Browse the repository at this point in the history
Summary:
Swapped NSUInteger to NSInteger in public headers. Fixed a test in IGListSectionMapTests.m to pass with NSInteger. For issue #200!

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/CONTRIBUTING.md)
Closes #205

Differential Revision: D4191521

Pulled By: rnystrom

fbshipit-source-id: 3f15c5ee3f8ed2d382de2602912a2e998bfbcbba
  • Loading branch information
surayashivji authored and Facebook Github Bot committed Nov 16, 2016
1 parent 1e7fa06 commit e2fbb68
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This release closes the [2.0.0 milestone](https://github.com/Instagram/IGListKit

- Diff result method `-resultWithUpdatedMovesAsDeleteInserts` removed and replaced with `-resultForBatchUpdates` [(b5aa5e3)](https://github.com/Instagram/IGListKit/commit/b5aa5e39002854c947e777c11ae241f67f24d19c)
- `IGListDiffable` equality method changed from `isEqual:` to `isEqualToDiffableObject:` [(ab890fc)](https://github.com/Instagram/IGListKit/commit/ab890fc6070f170a2db5a383a6296e62dcf75678)
- Change `NSUInteger` to `NSInteger` in public API [Suraya Shivji](https://github.com/surayashivji) [(#200)](https://github.com/Instagram/IGListKit/issues/200)


### Enhancements

Expand Down
8 changes: 4 additions & 4 deletions Source/IGListAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ IGLK_SUBCLASSING_RESTRICTED
*/
- (instancetype)initWithUpdater:(id <IGListUpdatingDelegate>)updatingDelegate
viewController:(nullable UIViewController *)viewController
workingRangeSize:(NSUInteger)workingRangeSize NS_DESIGNATED_INITIALIZER;
workingRangeSize:(NSInteger)workingRangeSize NS_DESIGNATED_INITIALIZER;

/**
Perform an update from the previous state of the data source. This is analagous to calling
Expand Down Expand Up @@ -128,7 +128,7 @@ IGLK_SUBCLASSING_RESTRICTED
@return The section index of the list if it exists, otherwise `NSNotFound`.
*/
- (NSUInteger)sectionForSectionController:(IGListSectionController <IGListSectionType> *)sectionController;
- (NSInteger)sectionForSectionController:(IGListSectionController <IGListSectionType> *)sectionController;

/**
Returns the section controller for the specified object. Constant time lookup.
Expand Down Expand Up @@ -157,7 +157,7 @@ IGLK_SUBCLASSING_RESTRICTED
@return The object for the specified section, or `nil` if the section does not exist.
*/
- (nullable id)objectAtSection:(NSUInteger)section;
- (nullable id)objectAtSection:(NSInteger)section;

/**
Returns the section corresponding to the specified object in the list. Constant time lookup.
Expand All @@ -166,7 +166,7 @@ IGLK_SUBCLASSING_RESTRICTED
@return The section index of `object` if found, otherwise `NSNotFound`.
*/
- (NSUInteger)sectionForObject:(id)object;
- (NSInteger)sectionForObject:(id)object;

/**
Returns a copy of all the objects currently powering the adapter.
Expand Down
10 changes: 5 additions & 5 deletions Source/IGListAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (void)dealloc {

- (instancetype)initWithUpdater:(id <IGListUpdatingDelegate>)updatingDelegate
viewController:(UIViewController *)viewController
workingRangeSize:(NSUInteger)workingRangeSize {
workingRangeSize:(NSInteger)workingRangeSize {
IGAssertMainThread();
IGParameterAssert(updatingDelegate);

Expand Down Expand Up @@ -290,7 +290,7 @@ - (void)reloadObjects:(NSArray *)objects {

#pragma mark - List Items & Sections

- (NSUInteger)sectionForSectionController:(IGListSectionController <IGListSectionType> *)sectionController {
- (NSInteger)sectionForSectionController:(IGListSectionController <IGListSectionType> *)sectionController {
IGAssertMainThread();
IGParameterAssert(sectionController != nil);

Expand All @@ -312,13 +312,13 @@ - (id)objectForSectionController:(IGListSectionController <IGListSectionType> *)
return [self.sectionMap objectForSection:section];
}

- (id)objectAtSection:(NSUInteger)section {
- (id)objectAtSection:(NSInteger)section {
IGAssertMainThread();

return [self.sectionMap objectForSection:section];
}

- (NSUInteger)sectionForObject:(id)item {
- (NSInteger)sectionForObject:(id)item {
IGAssertMainThread();
IGParameterAssert(item != nil);

Expand Down Expand Up @@ -676,7 +676,7 @@ - (CGSize)containerSize {
return UIEdgeInsetsInsetRect(self.collectionView.bounds, self.collectionView.contentInset).size;
}

- (NSUInteger)indexForCell:(UICollectionViewCell *)cell sectionController:(nonnull IGListSectionController<IGListSectionType> *)sectionController {
- (NSInteger)indexForCell:(UICollectionViewCell *)cell sectionController:(nonnull IGListSectionController<IGListSectionType> *)sectionController {
IGAssertMainThread();
IGParameterAssert(cell != nil);
IGParameterAssert(sectionController != nil);
Expand Down
4 changes: 2 additions & 2 deletions Source/IGListCollectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
@return The index of the cell or `NSNotFound` if it does not exist in the collection.
*/
- (NSUInteger)indexForCell:(UICollectionViewCell *)cell
- (NSInteger)indexForCell:(UICollectionViewCell *)cell
sectionController:(IGListSectionController<IGListSectionType> *)sectionController;

/**
Expand Down Expand Up @@ -76,7 +76,7 @@ NS_ASSUME_NONNULL_BEGIN
@return The section index of the controller if found, otherwise `NSNotFound`.
*/
- (NSUInteger)sectionForSectionController:(IGListSectionController<IGListSectionType> *)sectionController;
- (NSInteger)sectionForSectionController:(IGListSectionController<IGListSectionType> *)sectionController;

/**
Dequeues a cell from the collection view reuse pool.
Expand Down
2 changes: 1 addition & 1 deletion Source/IGListDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
An option for how to do comparisons between similar objects.
*/
typedef NS_ENUM(NSUInteger, IGListDiffOption) {
typedef NS_ENUM(NSInteger, IGListDiffOption) {
/**
Compare objects using pointer personality.
*/
Expand Down
2 changes: 1 addition & 1 deletion Source/IGListExperiments.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
Bitmask-able options used for pre-release feature testing.
*/
typedef NS_OPTIONS (NSUInteger, IGListExperiment) {
typedef NS_OPTIONS (NSInteger, IGListExperiment) {
IGListExperimentNone = 1 << 1,
};

Expand Down
4 changes: 2 additions & 2 deletions Source/IGListIndexSetResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
@see `-[IGListDiffable diffIdentifier]`.
*/
- (NSUInteger)oldIndexForIdentifier:(id<NSObject>)identifier;
- (NSInteger)oldIndexForIdentifier:(id<NSObject>)identifier;

/**
Returns the index of the object with the specified identifier *after* the diff.
Expand All @@ -65,7 +65,7 @@ NS_ASSUME_NONNULL_BEGIN
@see `-[IGListDiffable diffIdentifier]`.
*/
- (NSUInteger)newIndexForIdentifier:(id<NSObject>)identifier;
- (NSInteger)newIndexForIdentifier:(id<NSObject>)identifier;

/**
Creates a new result object with operations safe for use in `UITableView` and `UICollectionView` batch updates.
Expand Down
4 changes: 2 additions & 2 deletions Source/IGListIndexSetResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ - (IGListIndexSetResult *)resultForBatchUpdates {
newIndexMap:_newIndexMap];
}

- (NSUInteger)oldIndexForIdentifier:(id<NSObject>)identifier {
- (NSInteger)oldIndexForIdentifier:(id<NSObject>)identifier {
NSNumber *index = [_oldIndexMap objectForKey:identifier];
return index == nil ? NSNotFound : [index integerValue];
}

- (NSUInteger)newIndexForIdentifier:(id<NSObject>)identifier {
- (NSInteger)newIndexForIdentifier:(id<NSObject>)identifier {
NSNumber *index = [_newIndexMap objectForKey:identifier];
return index == nil ? NSNotFound : [index integerValue];
}
Expand Down
4 changes: 2 additions & 2 deletions Source/IGListMoveIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ NS_ASSUME_NONNULL_BEGIN
/**
An index in the old collection.
*/
@property (nonatomic, assign, readonly) NSUInteger from;
@property (nonatomic, assign, readonly) NSInteger from;

/**
An index in the new collection.
*/
@property (nonatomic, assign, readonly) NSUInteger to;
@property (nonatomic, assign, readonly) NSInteger to;

/**
:nodoc:
Expand Down
10 changes: 5 additions & 5 deletions Source/IGListMoveIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@implementation IGListMoveIndex

- (instancetype)initWithFrom:(NSUInteger)from to:(NSUInteger)to {
- (instancetype)initWithFrom:(NSInteger)from to:(NSInteger)to {
if (self = [super init]) {
_from = from;
_to = to;
Expand All @@ -29,16 +29,16 @@ - (BOOL)isEqual:(id)object {
return YES;
}
if ([object isKindOfClass:[IGListMoveIndex class]]) {
NSUInteger f1 = self.from, f2 = [object from];
NSUInteger t1 = self.to, t2 = [object to];
const NSInteger f1 = self.from, f2 = [object from];
const NSInteger t1 = self.to, t2 = [object to];
return f1 == f2 && t1 == t2;
}
return NO;
}

- (NSComparisonResult)compare:(id)object {
const NSUInteger right = [object from];
const NSUInteger left = [self from];
const NSInteger right = [object from];
const NSInteger left = [self from];
if (left == right) {
return NSOrderedSame;
} else if (left < right) {
Expand Down
10 changes: 5 additions & 5 deletions Source/IGListStackedSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ - (void)reloadData {
IGAssert(self.sectionControllersForItems.count == self.flattenedNumberOfItems, @"Controller map does not equal total number of items");
}

- (IGListSectionController <IGListSectionType> *)sectionControllerForObjectIndex:(NSUInteger)itemIndex {
- (IGListSectionController <IGListSectionType> *)sectionControllerForObjectIndex:(NSInteger)itemIndex {
return self.sectionControllersForItems[itemIndex];
}

- (NSUInteger)offsetForSectionController:(IGListSectionController<IGListSectionType> *)sectionController {
- (NSInteger)offsetForSectionController:(IGListSectionController<IGListSectionType> *)sectionController {
const NSUInteger index = [self.sectionControllers indexOfObject:sectionController];
IGAssert(index != NSNotFound, @"Querying offset for an undocumented section controller");
return [self.sectionControllerOffsets[index] integerValue];
}

- (NSUInteger)localIndexForSectionController:(IGListSectionController<IGListSectionType> *)sectionController index:(NSUInteger)index {
- (NSInteger)localIndexForSectionController:(IGListSectionController<IGListSectionType> *)sectionController index:(NSInteger)index {
const NSUInteger offset = [self offsetForSectionController:sectionController];
IGAssert(offset <= index, @"Section controller offset must be less than or equal to the item index");
return index - offset;
Expand Down Expand Up @@ -155,7 +155,7 @@ - (CGSize)containerSize {
return [self.collectionContext containerSize];
}

- (NSUInteger)indexForCell:(UICollectionViewCell *)cell sectionController:(IGListSectionController<IGListSectionType> *)sectionController {
- (NSInteger)indexForCell:(UICollectionViewCell *)cell sectionController:(IGListSectionController<IGListSectionType> *)sectionController {
const NSUInteger index = [self.collectionContext indexForCell:cell sectionController:self];
return [self localIndexForSectionController:sectionController index:index];
}
Expand Down Expand Up @@ -183,7 +183,7 @@ - (void)deselectItemAtIndex:(NSInteger)index sectionController:(IGListSectionCon
[self.collectionContext deselectItemAtIndex:localIndex sectionController:self animated:animated];
}

- (NSUInteger)sectionForSectionController:(IGListSectionController<IGListSectionType> *)sectionController {
- (NSInteger)sectionForSectionController:(IGListSectionController<IGListSectionType> *)sectionController {
return [self.collectionContext sectionForSectionController:self];
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Internal/IGListMoveIndexInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface IGListMoveIndex ()

- (instancetype)initWithFrom:(NSUInteger)from to:(NSUInteger)to NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrom:(NSInteger)from to:(NSInteger)to NS_DESIGNATED_INITIALIZER;

@end

Expand Down
10 changes: 5 additions & 5 deletions Source/Internal/IGListSectionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ IGLK_SUBCLASSING_RESTRICTED
@return A section controller.
*/
- (nullable IGListSectionController <IGListSectionType> *)sectionControllerForSection:(NSUInteger)section;
- (nullable IGListSectionController <IGListSectionType> *)sectionControllerForSection:(NSInteger)section;

/**
Fetch the object for a section
Expand All @@ -56,7 +56,7 @@ IGLK_SUBCLASSING_RESTRICTED
@return The object corresponding to the section.
*/
- (id)objectForSection:(NSUInteger)section;
- (id)objectForSection:(NSInteger)section;

/**
Fetch a section controller given an object. Can return nil.
Expand All @@ -74,7 +74,7 @@ IGLK_SUBCLASSING_RESTRICTED
@return The section index of the given section controller if it exists, NSNotFound otherwise.
*/
- (NSUInteger)sectionForSectionController:(id)sectionController;
- (NSInteger)sectionForSectionController:(id)sectionController;

/**
Look up the section index for an object.
Expand All @@ -83,7 +83,7 @@ IGLK_SUBCLASSING_RESTRICTED
@return The section index of the given object if it exists, NSNotFound otherwise.
*/
- (NSUInteger)sectionForObject:(id)object;
- (NSInteger)sectionForObject:(id)object;

/**
Remove all saved objects and section controllers.
Expand All @@ -100,7 +100,7 @@ IGLK_SUBCLASSING_RESTRICTED
@param block A block object to operate on entries in the section controller map.
*/
- (void)enumerateUsingBlock:(void (^)(id object, IGListSectionController<IGListSectionType> *sectionController, NSUInteger section, BOOL *stop))block;
- (void)enumerateUsingBlock:(void (^)(id object, IGListSectionController<IGListSectionType> *sectionController, NSInteger section, BOOL *stop))block;

/**
:nodoc:
Expand Down
10 changes: 5 additions & 5 deletions Source/Internal/IGListSectionMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ - (instancetype)initWithMapTable:(NSMapTable *)mapTable {

#pragma mark - Public API

- (NSUInteger)sectionForSectionController:(IGListSectionController <IGListSectionType> *)sectionController {
- (NSInteger)sectionForSectionController:(IGListSectionController <IGListSectionType> *)sectionController {
IGParameterAssert(sectionController != nil);

NSNumber *index = [self.sectionControllerToSectionMap objectForKey:sectionController];
return index != nil ? [index unsignedIntegerValue] : NSNotFound;
}

- (IGListSectionController <IGListSectionType> *)sectionControllerForSection:(NSUInteger)section {
- (IGListSectionController <IGListSectionType> *)sectionControllerForSection:(NSInteger)section {
return [self.sectionControllerToObjectMap objectForKey:[self objectForSection:section]];
}

Expand All @@ -74,7 +74,7 @@ - (void)updateWithObjects:(NSArray *)objects sectionControllers:(NSArray *)secti
return [self.sectionControllerToObjectMap objectForKey:object];
}

- (id)objectForSection:(NSUInteger)section {
- (id)objectForSection:(NSInteger)section {
NSArray *objects = self.objects;
if (section < objects.count) {
return objects[section];
Expand All @@ -83,7 +83,7 @@ - (id)objectForSection:(NSUInteger)section {
}
}

- (NSUInteger)sectionForObject:(id)object {
- (NSInteger)sectionForObject:(id)object {
IGParameterAssert(object != nil);

id sectionController = [self sectionControllerForObject:object];
Expand Down Expand Up @@ -111,7 +111,7 @@ - (void)updateObject:(id)object {
self.objects = [mobjects copy];
}

- (void)enumerateUsingBlock:(void (^)(id object, IGListSectionController <IGListSectionType> *sectionController, NSUInteger section, BOOL *stop))block {
- (void)enumerateUsingBlock:(void (^)(id object, IGListSectionController <IGListSectionType> *sectionController, NSInteger section, BOOL *stop))block {
IGParameterAssert(block != nil);

BOOL stop = NO;
Expand Down
6 changes: 3 additions & 3 deletions Source/Internal/IGListStackedSectionControllerInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ IGListScrollDelegate
@property (nonatomic, copy) NSArray<NSNumber *> *sectionControllerOffsets;

/// A cached collection of the number of items summed from each section controller in the stack.
@property (nonatomic, assign) NSUInteger flattenedNumberOfItems;
@property (nonatomic, assign) NSInteger flattenedNumberOfItems;

/// A counted set of the visible section controllers, used to forward granular display events to child section controllers
@property (nonatomic, strong, readonly) NSCountedSet *visibleSectionControllers;

- (IGListSectionController <IGListSectionType> *)sectionControllerForObjectIndex:(NSUInteger)itemIndex;
- (NSUInteger)offsetForSectionController:(IGListSectionController<IGListSectionType> *)sectionController;
- (IGListSectionController <IGListSectionType> *)sectionControllerForObjectIndex:(NSInteger)itemIndex;
- (NSInteger)offsetForSectionController:(IGListSectionController<IGListSectionType> *)sectionController;

@end
2 changes: 1 addition & 1 deletion Tests/IGListSectionMapTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ - (void)test_whenEnumeratingMap_withStopFlagSet_thatEnumerationEndsEarly {
IGListSectionMap *map = [[IGListSectionMap alloc] initWithMapTable:[NSMapTable strongToStrongObjectsMapTable]];
[map updateWithObjects:objects sectionControllers:sectionControllers];
__block NSInteger counter = 0;
[map enumerateUsingBlock:^(id item, IGListSectionController<IGListSectionType> * sectionController, NSUInteger section, BOOL *stop) {
[map enumerateUsingBlock:^(id item, IGListSectionController<IGListSectionType> * sectionController, NSInteger section, BOOL *stop) {
counter++;
*stop = section == 1;
}];
Expand Down
6 changes: 3 additions & 3 deletions Tests/Objects/IGTestDelegateController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

@property (nonatomic, copy) void (^itemUpdateBlock)();
@property (nonatomic, copy) void (^cellConfigureBlock)(IGTestDelegateController *);
@property (nonatomic, assign, readonly) NSUInteger updateCount;
@property (nonatomic, assign, readonly) NSInteger updateCount;

@property (nonatomic, assign) NSUInteger willDisplayCount;
@property (nonatomic, assign) NSUInteger didEndDisplayCount;
@property (nonatomic, assign) NSInteger willDisplayCount;
@property (nonatomic, assign) NSInteger didEndDisplayCount;
@property (nonatomic, strong) NSCountedSet *willDisplayCellIndexes;
@property (nonatomic, strong) NSCountedSet *didEndDisplayCellIndexes;

Expand Down

0 comments on commit e2fbb68

Please sign in to comment.