[swift-evolution] [Review] SE-0018 Flexible Memberwise Initialization
Thorsten Seitz
trsfoo at googlemail.com
Fri Jan 8 03:22:09 CST 2016
> Am 07.01.2016 um 20:30 schrieb Matthew Johnson via swift-evolution <swift-evolution at swift.org>:
>
> Here is an example where partial memberwise initialization would apply. It is similar to something in a real project:
>
> public class FontPicker: UIControl {
> public let fonts: [UIFont]
>
> public var fontSize: CGFloat = 22
> public var foregroundColor: UIColor = UIColor.darkGrayColor()
> public var backgroundColor: UIColor = UIColor.whiteColor()
> // A bunch of other appearance attributes here
>
> private let collectionView: UICollectionView
> private let layout: UICollectionViewLayout
> // other internal state required by the implementation
>
> public memberwise init(...) {
> // configure the collection view and add it as a subview
> }
> }
>
> A couple points are relevant here:
>
> 1. Memberwise initialization is very valuable for the appearance attributes, but is useless if it exposes our implementation details.
The appearance attributes probably won’t change within an app (would be strange to have the FontPicker sometimes have this font size then that, even stranger regarding the colors) but would only be different between different apps, or at least not change alone but in concert with all other UIControls.
So wouldn’t it be more appropriate for this example to instead use the existing UIAppearance functionality? Then the memberwise initializer would not really be needed here as configuring the appearance would not be done in the initializer.
-Thorsten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160108/a4fa523e/attachment.html>
More information about the swift-evolution
mailing list