Last active
April 8, 2019 03:24
-
-
Save marinofelipe/2f395766ac58b288d55fc08c79cd3fca to your computer and use it in GitHub Desktop.
Blog post / Dynamic Type - Extending Optional when the wrapped value is of type UIFont, so we can return the custom font object or precondition failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Optional where Wrapped == UIFont { | |
var unwrapped: Wrapped { | |
switch self { | |
case .some(let font): return font | |
case .none: | |
preconditionFailure(""" | |
Could not load font from available fonts: | |
\(UIFont.familyNames.joined(separator: ", ")) | |
""") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment