this questions follows on from Is there a neat way to represent a fraction as an attributed string?.
i have a function that provides a font for a fraction string
func fractionFont() -> UIFont {
let pointSize = CGFloat(20.0)
let systemFontDescriptor = UIFont.systemFontOfSize(pointSize, weight: UIFontWeightLight).fontDescriptor()
let fractionFontDescriptor = systemFontDescriptor.fontDescriptorByAddingAttributes(
[
UIFontDescriptorFeatureSettingsAttribute: [
[
UIFontFeatureTypeIdentifierKey: kFractionsType,
UIFontFeatureSelectorIdentifierKey: kDiagonalFractionsSelector,
], ]
] )
return UIFont(descriptor: fractionFontDescriptor, size: pointSize)
}
and i use in it for a label property in SomeClass
class SomeClass {
@IBOutlet weak var fractionLabel: UILabel! {
didSet {
fractionLabel.text = "1/2"
fractionLabel.font = fractionFont()
}
}
}
say i want to use fractionFont
method again in AnotherClass
i guess copying the code is not a great idea. i was also advised in another post to use so called Singleton
classes sparingly, so what's the best approach for this?
- thanks