Skip to content

Added Support for System Weighted Fonts#301

Merged
timbodeit merged 2 commits intotombenner:masterfrom
Stunner:system-weighted-fonts
Nov 9, 2015
Merged

Added Support for System Weighted Fonts#301
timbodeit merged 2 commits intotombenner:masterfrom
Stunner:system-weighted-fonts

Conversation

@Stunner
Copy link
Copy Markdown
Collaborator

@Stunner Stunner commented Jul 9, 2015

No description provided.

@Stunner
Copy link
Copy Markdown
Collaborator Author

Stunner commented Jul 9, 2015

Failed the test due to #302.

@Stunner
Copy link
Copy Markdown
Collaborator Author

Stunner commented Nov 5, 2015

@timbodeit please review this pull request. @tombenner please take a look.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just something that came to my mind (wouldn't make any effort to change it):
Adding this check to the last else block would require less nesting

@timbodeit
Copy link
Copy Markdown
Collaborator

Looks good to me. I'd wait a bit to give @tombenner some time to veto, but after that it's good to merge 👍

@tombenner
Copy link
Copy Markdown
Owner

LGTM 👍

timbodeit added a commit that referenced this pull request Nov 9, 2015
Added Support for System Weighted Fonts
@timbodeit timbodeit merged commit c83fc08 into tombenner:master Nov 9, 2015
@timbodeit
Copy link
Copy Markdown
Collaborator

@Stunner Please have a look at the CI failures

@Stunner
Copy link
Copy Markdown
Collaborator Author

Stunner commented Nov 9, 2015

I am not able to reproduce this issue locally. Running the test target from iOS 7.1 (Xcode 6.4) , 8.1, 8.2, 8.3 (Xcode 7.1) all works for me. It appears it is complaining of a compilation error of a class method on UIFont. I am thinking it is due to an early version of Xcode running on the CI server. Can someone with access to the Travis CI for this project investigate further ( @tombenner )?

@timbodeit
Copy link
Copy Markdown
Collaborator

You have full access to Travis CI for the project.
The main configuration is done through the .travis.yml file checked into the repository.
On the Travis website there is only a pretty minimalistic set of preferences (such as setting environment variables or limiting concurrent builds). Access to the Travis build settings is also tied to the repository permissions on GitHub. Any Collaborator can also modify the settings on Travis.

The problem is that UIFontWeightBlack etc are only available on iOS 8.2 or higher. systemFontOfSize:weight: is part of iOS 7.0, but was only meant to be used with custom floats at that point in time.

The compile error will only happen, if you're using an iOS SDK older than 8.2. If you're using a newer SDK, this will probably (not tested) still cause issues, but rather in the form of a runtime crash than a compile time error.

The reason why you're not able to reproduce this issue on your machine is that Xcode 6.4 uses the iphoneos8.4 SDK by default. When not specifying Xcode versions in the .travis.yml, Travis uses Xcode 6.1 which builds against iphoneos8.1. If you're interested, you can find more information about building Objective-C projects on Travis here.

I'm not entirely sure yet how to properly fix this, but I think we're going to need two additional checks:

  1. At compile time: Checking if the SDK we're using even defines this symbol (through an #ifdef or similar). If we don't check this, the build will fail.
  2. At run time: Checking if the iOS version of the device running the App (which can be lower than the SDK version) supports the attribute. If we don't check this, the build will succeed, but the App may crash on versions lower than iOS 8.2.

I'm going to do some research on what the best way to handle this is.

In the meantime, it would be awesome if you could add test coverage for the changes you made, to make sure they actually work as expected at runtime.
A unit test for this should account for different behavior under different iOS Versions (specifically iOS 8.1 and lower and iOS 8.2 or higher).

Also it would be a good idea to run the tests against multiple iOS versions on Travis. I'll probably take care of that in the next couple of days.

@timbodeit
Copy link
Copy Markdown
Collaborator

So to fix this, replace

if ([[UIFont class] respondsToSelector:@selector(systemFontOfSize:weight:)]) {
  /* ... */
}

(iOS 7.0 device version run time only check)

by

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_2
  if (&UIFontWeightBlack != NULL) {
    /* ... */
  }
#endif

(iOS 8.2 SDK compile time and iOS 8.2 device version run time time check)

Nonetheless, if you'd be willing to add one, a unit test can't hurt 😉


The first line will check that the base SDK version is at least 8.2 at compile time.
The second line will check for the availability of UIFontWeightBlack at run time.

More info about this on stackoverflow and in Apple's SDK Compatibility Guide.
(Specifically in the Using Weakly Linked Methods, Functions, and Symbols and Conditionally Compiling for Different SDKs sections)

@timbodeit
Copy link
Copy Markdown
Collaborator

I have reset master to the commit before merging your pull request, leaving the previous state in a new branch named weighted-system-fonts.
Please open another PR, when you've fixed the CI issues.

@Stunner Stunner mentioned this pull request Nov 13, 2015
@Stunner
Copy link
Copy Markdown
Collaborator Author

Stunner commented Nov 13, 2015

@timbodeit Cool deal, thanks for the info and suggestions. Followed your suggestions and just issued a pull request: #311 assigned it to you to review and merge in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants