Skip to content

Instantly share code, notes, and snippets.

@marinofelipe
Last active April 8, 2019 03:24
Show Gist options
  • Save marinofelipe/2f395766ac58b288d55fc08c79cd3fca to your computer and use it in GitHub Desktop.
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
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