Skip to content

Commit

Permalink
Address warnings in Xcode >= 9.3 about using %zd for NSInteger (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adlai-Holler committed Jul 13, 2018
1 parent 8986838 commit af7f71f
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 23 deletions.
9 changes: 3 additions & 6 deletions Source/ASConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@

/// Not too performance-sensitive here.

/// Get this from C++, without the extra exception handling.
#define autotype __auto_type

@implementation ASConfiguration

- (instancetype)initWithDictionary:(NSDictionary *)dictionary
{
if (self = [super init]) {
if (dictionary != nil) {
autotype featureStrings = ASDynamicCast(dictionary[@"experimental_features"], NSArray);
autotype version = ASDynamicCast(dictionary[@"version"], NSNumber).integerValue;
let featureStrings = ASDynamicCast(dictionary[@"experimental_features"], NSArray);
let version = ASDynamicCast(dictionary[@"version"], NSNumber).integerValue;
if (version != ASConfigurationSchemaCurrentVersion) {
NSLog(@"Texture warning: configuration schema is old version (%zd vs %zd)", version, ASConfigurationSchemaCurrentVersion);
NSLog(@"Texture warning: configuration schema is old version (%ld vs %ld)", (long)version, (long)ASConfigurationSchemaCurrentVersion);
}
self.experimentalFeatures = ASExperimentalFeaturesFromArray(featureStrings);
} else {
Expand Down
4 changes: 2 additions & 2 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,7 @@ - (void)_insertSubnode:(ASDisplayNode *)subnode atSubnodeIndex:(NSInteger)subnod
NSUInteger subnodesCount = _subnodes.count;
__instanceLock__.unlock();
if (subnodeIndex > subnodesCount || subnodeIndex < 0) {
ASDisplayNodeFailAssert(@"Cannot insert a subnode at index %zd. Count is %zd", subnodeIndex, subnodesCount);
ASDisplayNodeFailAssert(@"Cannot insert a subnode at index %ld. Count is %ld", (long)subnodeIndex, (long)subnodesCount);
return;
}

Expand Down Expand Up @@ -2540,7 +2540,7 @@ - (void)_insertSubnode:(ASDisplayNode *)subnode atIndex:(NSInteger)idx
ASDN::MutexLocker l(__instanceLock__);

if (idx > _subnodes.count || idx < 0) {
ASDisplayNodeFailAssert(@"Cannot insert a subnode at index %zd. Count is %zd", idx, _subnodes.count);
ASDisplayNodeFailAssert(@"Cannot insert a subnode at index %ld. Count is %ld", (long)idx, (long)_subnodes.count);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Details/ASElementMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ - (BOOL)sectionIndexIsValid:(NSInteger)section assert:(BOOL)assert
NSInteger sectionCount = _sectionsOfItems.count;
if (section >= sectionCount || section < 0) {
if (assert) {
ASDisplayNodeFailAssert(@"Invalid section index %zd when there are only %zd sections!", section, sectionCount);
ASDisplayNodeFailAssert(@"Invalid section index %ld when there are only %ld sections!", (long)section, (long)sectionCount);
}
return NO;
} else {
Expand Down Expand Up @@ -272,7 +272,7 @@ - (BOOL)itemIndexPathIsValid:(NSIndexPath *)indexPath assert:(BOOL)assert item:(
NSInteger item = indexPath.item;
if (item >= itemCount || item < 0) {
if (assert) {
ASDisplayNodeFailAssert(@"Invalid item index %zd in section %zd which only has %zd items!", item, section, itemCount);
ASDisplayNodeFailAssert(@"Invalid item index %ld in section %ld which only has %ld items!", (long)item, (long)section, (long)itemCount);
}
return NO;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASIntegerMap.mm
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ - (id)copyWithZone:(NSZone *)zone
// { 1->2 3->4 5->6 }
NSMutableString *str = [NSMutableString string];
for (let &e : _map) {
[str appendFormat:@" %zd->%zd", e.first, e.second];
[str appendFormat:@" %ld->%ld", (long)e.first, (long)e.second];
}
// Remove leading space
if (str.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions Source/Private/ASTwoDimensionalArrayUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ void ASDeleteElementsInTwoDimensionalArrayAtIndexPaths(NSMutableArray *mutableAr
for (NSIndexPath *indexPath in indexPaths) {
NSInteger section = indexPath.section;
if (section >= mutableArray.count) {
ASDisplayNodeCFailAssert(@"Invalid section index %zd – only %zd sections", section, mutableArray.count);
ASDisplayNodeCFailAssert(@"Invalid section index %ld – only %ld sections", (long)section, (long)mutableArray.count);
continue;
}

NSMutableArray *subarray = mutableArray[section];
NSInteger item = indexPath.item;
if (item >= subarray.count) {
ASDisplayNodeCFailAssert(@"Invalid item index %zd – only %zd items in section %zd", item, subarray.count, section);
ASDisplayNodeCFailAssert(@"Invalid item index %ld – only %ld items in section %ld", (long)item, (long)subarray.count, (long)section);
continue;
}
[subarray removeObjectAtIndex:item];
Expand Down
2 changes: 1 addition & 1 deletion Source/Private/TextExperiment/Component/ASTextLine.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ - (CGFloat)right {
- (NSString *)description {
NSMutableString *desc = @"".mutableCopy;
NSRange range = self.range;
[desc appendFormat:@"<ASTextLine: %p> row:%zd range:%tu,%tu",self, self.row, range.location, range.length];
[desc appendFormat:@"<ASTextLine: %p> row:%ld range:%tu,%tu", self, (long)self.row, range.location, range.length];
[desc appendFormat:@" position:%@",NSStringFromCGPoint(self.position)];
[desc appendFormat:@" bounds:%@",NSStringFromCGRect(self.bounds)];
return desc;
Expand Down
2 changes: 1 addition & 1 deletion Source/Private/_ASCoreAnimationExtras.mm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ UIViewContentMode ASDisplayNodeUIContentModeFromNSString(NSString *string)
return e.string;
}
}
ASDisplayNodeCAssert(contentMode == UIViewContentModeRedraw, @"Encountered an unknown contentMode %zd. Is this a new version of iOS?", contentMode);
ASDisplayNodeCAssert(contentMode == UIViewContentModeRedraw, @"Encountered an unknown contentMode %ld. Is this a new version of iOS?", (long)contentMode);
// Redraw is ok to return nil.
return nil;
}
Expand Down
16 changes: 8 additions & 8 deletions Source/Private/_ASHierarchyChangeSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ - (void)_validateUpdate
NSInteger deletedSectionCount = _deletedSections.count;
// Assert that the new section count is correct.
if (newSectionCount != oldSectionCount + insertedSectionCount - deletedSectionCount) {
ASFailUpdateValidation(@"Invalid number of sections. The number of sections after the update (%zd) must be equal to the number of sections before the update (%zd) plus or minus the number of sections inserted or deleted (%tu inserted, %tu deleted)", newSectionCount, oldSectionCount, insertedSectionCount, deletedSectionCount);
ASFailUpdateValidation(@"Invalid number of sections. The number of sections after the update (%ld) must be equal to the number of sections before the update (%ld) plus or minus the number of sections inserted or deleted (%ld inserted, %ld deleted)", (long)newSectionCount, (long)oldSectionCount, (long)insertedSectionCount, (long)deletedSectionCount);
return;
}

Expand All @@ -548,7 +548,7 @@ - (void)_validateUpdate
invalidSectionDelete = [_deletedSections indexGreaterThanIndex:oldSectionCount - 1];
}
if (invalidSectionDelete != NSNotFound) {
ASFailUpdateValidation(@"Attempt to delete section %zd but there are only %zd sections before the update.", invalidSectionDelete, oldSectionCount);
ASFailUpdateValidation(@"Attempt to delete section %ld but there are only %ld sections before the update.", (long)invalidSectionDelete, (long)oldSectionCount);
return;
}

Expand All @@ -558,14 +558,14 @@ - (void)_validateUpdate
NSInteger section = indexPath.section;
NSInteger item = indexPath.item;
if (section >= oldSectionCount) {
ASFailUpdateValidation(@"Attempt to delete item %zd from section %zd, but there are only %zd sections before the update.", item, section, oldSectionCount);
ASFailUpdateValidation(@"Attempt to delete item %ld from section %ld, but there are only %ld sections before the update.", (long)item, (long)section, (long)oldSectionCount);
return;
}

// Assert that item delete happened to a valid item.
NSInteger oldItemCount = _oldItemCounts[section];
if (item >= oldItemCount) {
ASFailUpdateValidation(@"Attempt to delete item %zd from section %zd, which only contains %zd items before the update.", item, section, oldItemCount);
ASFailUpdateValidation(@"Attempt to delete item %ld from section %ld, which only contains %ld items before the update.", (long)item, (long)section, (long)oldItemCount);
return;
}
}
Expand All @@ -577,14 +577,14 @@ - (void)_validateUpdate
NSInteger item = indexPath.item;
// Assert that item insert happened in a valid section.
if (section >= newSectionCount) {
ASFailUpdateValidation(@"Attempt to insert item %zd into section %zd, but there are only %zd sections after the update.", item, section, newSectionCount);
ASFailUpdateValidation(@"Attempt to insert item %ld into section %ld, but there are only %ld sections after the update.", (long)item, (long)section, (long)newSectionCount);
return;
}

// Assert that item delete happened to a valid item.
NSInteger newItemCount = _newItemCounts[section];
if (item >= newItemCount) {
ASFailUpdateValidation(@"Attempt to insert item %zd into section %zd, which only contains %zd items after the update.", item, section, newItemCount);
ASFailUpdateValidation(@"Attempt to insert item %ld into section %ld, which only contains %ld items after the update.", (long)item, (long)section, (long)newItemCount);
return;
}
}
Expand All @@ -598,7 +598,7 @@ - (void)_validateUpdate
invalidSectionInsert = [_insertedSections indexGreaterThanIndex:newSectionCount - 1];
}
if (invalidSectionInsert != NSNotFound) {
ASFailUpdateValidation(@"Attempt to insert section %zd but there are only %zd sections after the update.", invalidSectionInsert, newSectionCount);
ASFailUpdateValidation(@"Attempt to insert section %ld but there are only %ld sections after the update.", (long)invalidSectionInsert, (long)newSectionCount);
return;
}

Expand Down Expand Up @@ -631,7 +631,7 @@ - (void)_validateUpdate
NSInteger insertedItemCount = originalInsertedItems.count;
NSInteger deletedItemCount = originalDeletedItems.count;
if (newItemCount != oldItemCount + insertedItemCount - deletedItemCount) {
ASFailUpdateValidation(@"Invalid number of items in section %zd. The number of items after the update (%zd) must be equal to the number of items before the update (%zd) plus or minus the number of items inserted or deleted (%zd inserted, %zd deleted).", oldSection, newItemCount, oldItemCount, insertedItemCount, deletedItemCount);
ASFailUpdateValidation(@"Invalid number of items in section %ld. The number of items after the update (%ld) must be equal to the number of items before the update (%ld) plus or minus the number of items inserted or deleted (%ld inserted, %ld deleted).", (long)oldSection, (long)newItemCount, (long)oldItemCount, (long)insertedItemCount, (long)deletedItemCount);
return;
}
}
Expand Down

0 comments on commit af7f71f

Please sign in to comment.