I am adapting the `SwiftForms` library (https://github.com/ortuman/SwiftForms) for use in a project using Swift 2.0. The library includes various table cells preconfigured for use (switches, date pickers, check cells, steppers, etc). A change I've introduced is to use a protocol extension to make it possible to set a custom font. Here's the idea:
public protocol FormFontDefaults {
var titleLabelFont: UIFont { get }
}
public extension FormFontDefaults {
var titleLabelFont: UIFont { return UIFont.preferredFontForTextStyle(UIFontTextStyleBody) }
}The base cell conforms to the protocol so that the default font set in the protocol extension is used:
public class FormBaseCell: UITableViewCell, FormFontDefaults {
public func configure() {
titleLabel.font = titleLabelFont
}
}To set a custom font the idea is to override the protocol extension as follows:
public extension FormBaseCell {
var titleLabelFont: UIFont { return UIFont(… custom font) }
}If I do that inside the library the override works as expected.
But, the idea is that users can link to the library and set their own override (as shown above). However it doesn't seem possible. If I include the project as a framework dependency in a project and try to override the extension, the code will compile but it is never called, making it impossible to set a custom font.
Should this technique work?