Skip to content

Commit

Permalink
Fixed crash if font has no italic or bold trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Stemmle committed Aug 7, 2017
1 parent 195d18f commit de65a56
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions MarkdownKit/Classes/Extensions/UIFont+Traits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import UIKit

extension UIFont {

func withTraits(_ traits: UIFontDescriptorSymbolicTraits...) -> UIFont {
let descriptor = fontDescriptor
.withSymbolicTraits(UIFontDescriptorSymbolicTraits(traits))
return UIFont(descriptor: descriptor!, size: 0)
func withTraits(_ traits: UIFontDescriptorSymbolicTraits...) -> UIFont? {
guard let descriptor = fontDescriptor.withSymbolicTraits(UIFontDescriptorSymbolicTraits(traits)) else {
return nil
}
return UIFont(descriptor: descriptor, size: 0)
}

func bold() -> UIFont {
func bold() -> UIFont? {
return withTraits(.traitBold)
}

func italic() -> UIFont {
func italic() -> UIFont? {
return withTraits(.traitItalic)
}
}

0 comments on commit de65a56

Please sign in to comment.