I have a UIFont Class that looks like this:
struct FontHelper {
func defaultFont(size: CGFloat) -> UIFont {
return UIFont(name:"Helvetica", size: size)!
}
}
and I call the method like this"
let fonts = FontHelper.defaultFont(12)
However my app crashes with an unexpected found nil while wrapping optional?
Have no idea why?
Since you're adding your own personal functionality to a Type, I think you should use an extension, declare this extension outside of your class:
Now, the UIFont Type has this really cool functionality you just added.
Within your class, call it:
I hope you can see the power of extensions here, so take advantage of them in Swift!