Skip to content

Commit

Permalink
[Tests/Catalog] Suppress partial availability warnings (material-comp…
Browse files Browse the repository at this point in the history
…onents#2780)

* [Tests] Suppress partial availability warnings

`- UIFont systemFontOfSize:weight:` was not introduced until iOS 8.2. Although
most of the code was already performing runtime checks on the selector, the
compiler still emits warnings for the use of the selectors.

Closes 2779

* Use systemFontOfSize: instead of fontWithName:size:
  • Loading branch information
Robert Moore authored and ianegordon committed Jan 2, 2018
1 parent ae955a3 commit 25de372
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
11 changes: 10 additions & 1 deletion catalog/MaterialCatalog/MDCCatalogTiles.m
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,17 @@ void MDCCatalogDrawNavigationBarTile(CGRect frame, id<MDCColorScheme> colorSchem
NSMutableParagraphStyle* labelStyle = [NSMutableParagraphStyle new];
labelStyle.alignment = NSTextAlignmentCenter;

UIFont *font;
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
font = [UIFont systemFontOfSize:11 weight:UIFontWeightMedium];
#pragma clang diagnostic pop
} else {
font = [UIFont systemFontOfSize:11];
}
NSDictionary* labelFontAttributes = @{
NSFontAttributeName : [UIFont systemFontOfSize:11 weight: UIFontWeightMedium],
NSFontAttributeName : font,
NSForegroundColorAttributeName : textForeground,
NSParagraphStyleAttributeName : labelStyle
};
Expand Down
8 changes: 8 additions & 0 deletions components/Typography/tests/unit/SystemFontLoaderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ - (void)testWeights {

// Then
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
XCTAssertEqual([fontLoader lightFontOfSize:size],
[UIFont systemFontOfSize:size weight:UIFontWeightLight]);
XCTAssertEqual([fontLoader regularFontOfSize:size],
Expand All @@ -38,6 +40,7 @@ - (void)testWeights {
[UIFont systemFontOfSize:size weight:UIFontWeightMedium]);
XCTAssertEqual([fontLoader boldFontOfSize:size],
[UIFont systemFontOfSize:size weight:UIFontWeightSemibold]);
#pragma clang diagnostic pop
} else {
// Fallback on earlier versions
XCTAssertEqual([fontLoader lightFontOfSize:size],
Expand Down Expand Up @@ -110,7 +113,12 @@ - (void)testUIFontWeightMediumValue {
CGFloat MDCFontWeightMedium = (CGFloat)0.23;
// Ensure that our placehold value for UIFontWeightMedium matches the real value.
// We are defining it for < iOS 8.2 in MDCTypography.m
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
if (&UIFontWeightMedium != NULL) {
XCTAssertEqualWithAccuracy(UIFontWeightMedium, MDCFontWeightMedium, FLT_EPSILON);
}
#pragma clang diagnostic pop
}

@end
10 changes: 9 additions & 1 deletion components/Typography/tests/unit/TypographyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,15 @@ - (void)testFontFamilyMatchesSystemFontFamily {
// When
MDCFontTextStyle style = styleObject.integerValue;
UIFont *mdcFont = [UIFont mdc_preferredFontForMaterialTextStyle:style];
UIFont *systemFont = [UIFont systemFontOfSize:mdcFont.pointSize weight:UIFontWeightRegular];
UIFont *systemFont;
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
systemFont = [UIFont systemFontOfSize:mdcFont.pointSize weight:UIFontWeightRegular];
} else {
systemFont = [UIFont systemFontOfSize:mdcFont.pointSize];
}
#pragma clang diagnostic pop

// Then
XCTAssertEqualObjects(systemFont.familyName, mdcFont.familyName);
Expand Down

0 comments on commit 25de372

Please sign in to comment.