Provide a more Swifty template
AliSoftware opened this issue · 1 comments
AliSoftware commented
Given that Iconic is based on SwiftGen, it's easy to provide more than one template for the user to choose from.
- For people that still have to use ObjC, they can still use your current template.
- But for people that would use Iconic in a Swift-only environment, it would be much better to have a more Swifty template that takes advantage of nested values, enum functions and Mixins.
Template suggestion
// Swift-only template
// Create IconicFont Mixin. Because Mixins are awesome.
public protocol IconicFont {
public static func register()
public static func font(fontSize: CGFloat) -> UIFont!
public func attributedString(size: CGFloat, color: UIColor?) -> NSAttributedString!
public func image(size: CGFloat, color: UIColor?) -> UIImage!
public func unicodeString() -> String!
}
public extension IconicFont {
… implementation goes here …
}
public enum FontAwesomeIcon: IconicFont {
case Adjust
case Adn
case AlignCenter
…
// and it will get the IconicFont default implementations for free!
}
Usage
FontAwesomeIcon.register()
let font: UIFont = FontAwesomeIcon.font(size: 14)
let img: UIImage = FontAwesomeIcon.AlignCenter.image(size: 100, color: nil)
let icon = FontAwesomeIcon.AlignCenter
imageView.image = icon.image(size: imageView.bounds.size)
label.attributedText = icon.attributedString(size: 14)
dzenbot commented
Great idea!
Will def. try that out. I'm worried about having fragmented XP. If this happens, I think I would need to default to the swifty template I think.