Upgrade to Pro — share decks privately, control downloads, hide ads and more …

モダンなイニシャライザ

Elvis Shi
September 05, 2017

 モダンなイニシャライザ

モダンなイニシャライザの作り方

Elvis Shi

September 05, 2017
Tweet

More Decks by Elvis Shi

Other Decks in Programming

Transcript

  1. override init() { super.init() emplyedBy = "MAGES. 5pb. Game div"

    job = "iOS Developer" twitter = "@lovee" qiita = "@lovee" github = "el-hoshino" additionalInfo = "͍ͨͩ·ઈࢍస৬׆ಈதʘ(^o^)ʗ" class Speaker: Developer { } }
  2. ͜ΜͳΠχγϟϥΠζɺͨ͜͠ͱͳ͍͔ʁ let label = UILabel(frame: .zero) label.font = UIFont.systemFont(ofSize: 20)

    label.textAlignment = .center label.textColor = .blue label.numberOfLines = 1 // ...
  3. ͜ΜͳΠχγϟϥΠζɺͨ͜͠ͱͳ͍͔ʁ let label = UILabel(frame: .zero) label.font = UIFont.systemFont(ofSize: 20)

    label.textAlignment = .center label.textColor = .blue label.numberOfLines = 1 // ... ໘౗͍͘͞
 !
  4. ͜ΜͳΠχγϟϥΠζɺͨ͜͠ͱͳ͍͔ʁ let labelA = UILabel(frame: .zero) labelA.font = UIFont.systemFont(ofSize: 20)

    labelA.textAlignment = .center labelA.textColor = .blue labelA.numberOfLines = 1 // ... let labelB = UILabel(frame: .zero) labelB.font = UIFont.systemFont(ofSize: 14) labelB.textAlignment = .center labelB.textColor = .gray labelA.numberOfLines = 0 labelB.lineBreakMode = .byCharWrapping // ...
  5. ͜ΜͳΠχγϟϥΠζɺͨ͜͠ͱͳ͍͔ʁ let labelA = UILabel(frame: .zero) labelA.font = UIFont.systemFont(ofSize: 20)

    labelA.textAlignment = .center labelA.textColor = .blue labelA.numberOfLines = 1 // ... let labelB = UILabel(frame: .zero) labelB.font = UIFont.systemFont(ofSize: 14) labelB.textAlignment = .center labelB.textColor = .gray labelA.numberOfLines = 0 labelB.lineBreakMode = .byCharWrapping // ... ม਺໊ ؒҧ͑ͨ
 !
  6. ཧ૝ͳΠχγϟϥΠβʔ let label = UILabel(frame: .zero) { $0 .setFont(to: .systemFont(ofSize:

    20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) } Ұ౓Ͱੜ੒ͱઃఆͱ୅ೖ͕Ͱ͖Δ ಉ͡୯ޠΛ
 ෳ਺ճॻ͔ͳ͍ ϝιουνΣʔϯʹΑΔ खܰͳิ׬
  7. ཧ૝ͳΠχγϟϥΠβʔ let label = UILabel(frame: .zero) { $0 .setFont(to: .systemFont(ofSize:

    20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) } Ұ౓Ͱੜ੒ͱઃఆͱ୅ೖ͕Ͱ͖Δ ಉ͡୯ޠΛ
 ෳ਺ճॻ͔ͳ͍ ϝιουνΣʔϯʹΑΔ खܰͳิ׬ Ͳ͏͢Ε͹͜Μͳ
 ཧ૝తͳΠχγϟϥΠβʔ͕
 ࡞ΕΔͷ͔ͳ"
  8. ཧ૝ͳΠχγϟϥΠβʔ let label = UILabel(frame: .zero) { $0 .setFont(to: .systemFont(ofSize:

    20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) } Ұ౓Ͱੜ੒ͱઃఆͱ୅ೖ͕Ͱ͖Δ ಉ͡୯ޠΛ
 ෳ਺ճॻ͔ͳ͍ ϝιουνΣʔϯʹΑΔ खܰͳิ׬
  9. ҰൠతͳϝιουνΣʔϯ struct ChainableType { func doSomething() -> ChainableType { //

    return ... } func doAnotherThing() -> ChainableType { // return ... } // func ... }
  10. ҰൠతͳϝιουνΣʔϯ struct ChainableType { func doSomething() -> ChainableType { //

    return ... } func doAnotherThing() -> ChainableType { // return ... } // func ... } let object = ChainableType() .doSomething() .doAnotherThing() // .do...
  11. ҰൠతͳϝιουνΣʔϯ struct ChainableType { func doSomething() -> ChainableType { //

    return ... } func doAnotherThing() -> ChainableType { // return ... } // func ... } let object = ChainableType() .doSomething() .doAnotherThing() // .do... object.doSomething() ੜ੒࣌Ҏ֎Ͱ΋ νΣʔϯϝιου͕ݺ΂ͯ͠·͏!
  12. APIs in UILabelMaker public struct UILabelMaker { } extension UILabelMaker

    { public func setFont(to font: UIFont) -> UILabelMaker public func setTextColor(to color: UIColor) -> UILabelMaker public func setTextAlignment(to alignment: NSTextAlignment) -> UILabelMaker public func setNumberOfLines(to number: Int) -> UILabelMaker public func setLineBreakMode(to mode: NSLineBreakMode) -> UILabelMaker } extension UILabel { public static func make(withFrame frame: CGRect = default, by making: (UILabelMaker) -> UILabelMaker) -> UILabel }
  13. APIs in UILabelMaker public struct UILabelMaker { } extension UILabelMaker

    { public func setFont(to font: UIFont) -> UILabelMaker public func setTextColor(to color: UIColor) -> UILabelMaker public func setTextAlignment(to alignment: NSTextAlignment) -> UILabelMaker public func setNumberOfLines(to number: Int) -> UILabelMaker public func setLineBreakMode(to mode: NSLineBreakMode) -> UILabelMaker } extension UILabel { public static func make(withFrame frame: CGRect = default, by making: (UILabelMaker) -> UILabelMaker) -> UILabel } ʗਓ◕ ‿‿ ◕人ʘϫέΨϫΧϥφΠϤ
  14. APIs in UILabelMaker public struct UILabelMaker { } extension UILabelMaker

    { public func setFont(to font: UIFont) -> UILabelMaker public func setTextColor(to color: UIColor) -> UILabelMaker public func setTextAlignment(to alignment: NSTextAlignment) -> UILabelMaker public func setNumberOfLines(to number: Int) -> UILabelMaker public func setLineBreakMode(to mode: NSLineBreakMode) -> UILabelMaker } extension UILabel { public static func make(withFrame frame: CGRect = default, by making: (UILabelMaker) -> UILabelMaker) -> UILabel } ϝιου make(withFrame: by:) ͷ໭Γ஋ ΫϩʔδϟʔҾ਺ making ͷܕ UILabelMaker ͷೖྗΛ౉͔͢Β
 ࣮ߦͯ͠ UILabelMaker ͷग़ྗΛग़ؔ͢਺Λ
 Ҿ਺ making ͱͯ͠౉͍ͯͩ͘͠͞
  15. APIs in UILabelMaker public struct UILabelMaker { } extension UILabelMaker

    { public func setFont(to font: UIFont) -> UILabelMaker public func setTextColor(to color: UIColor) -> UILabelMaker public func setTextAlignment(to alignment: NSTextAlignment) -> UILabelMaker public func setNumberOfLines(to number: Int) -> UILabelMaker public func setLineBreakMode(to mode: NSLineBreakMode) -> UILabelMaker } extension UILabel { public static func make(withFrame frame: CGRect = default, by making: (UILabelMaker) -> UILabelMaker) -> UILabel } making ͷೖྗͱͯ͠ͷ UILabelMakerɻ
 making ʹ౉͢ඞཁ͕͋ΔͷͰɺ
 UILabel ͔Β UILabelMaker ʹ
 ੜ੒͢ΔΠχγϟϥΠβ͕ඞཁ making ͷग़ྗͱͯ͠ͷ UILabelMakerɻ
 ࠷ऴతʹ UILabel ͕ඞཁͳͷͰɺ
 UILabelMaker ͔Β UILabel Λ
 ग़ྗ͢Δϝιου͕ඞཁ
  16. APIs in UILabelMaker public struct UILabelMaker { } extension UILabelMaker

    { public func setFont(to font: UIFont) -> UILabelMaker public func setTextColor(to color: UIColor) -> UILabelMaker public func setTextAlignment(to alignment: NSTextAlignment) -> UILabelMaker public func setNumberOfLines(to number: Int) -> UILabelMaker public func setLineBreakMode(to mode: NSLineBreakMode) -> UILabelMaker } extension UILabel { public static func make(withFrame frame: CGRect = default, by making: (UILabelMaker) -> UILabelMaker) -> UILabel } ͦ΋ͦ΋ UILabelMaker Λ௨ͯ͡
 UILabel Λઃఆ͍ͯ͠ΔͷͰɺ
 UILabel ΛϓϩύςΟʔͱͯ͠
 อ࣋͢Δඞཁ͕͋Δ
  17. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabelMaker { public func setFont(to font: UIFont) -> UILabelMaker public func setTextColor(to color: UIColor) -> UILabelMaker public func setTextAlignment(to alignment: NSTextAlignment) -> UILabelMaker public func setNumberOfLines(to number: Int) -> UILabelMaker public func setLineBreakMode(to mode: NSLineBreakMode) -> UILabelMaker } extension UILabel { public static func make(withFrame frame: CGRect = default, by making: (UILabelMaker) -> UILabelMaker) -> UILabel }
  18. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabelMaker { public func setFont(to font: UIFont) -> UILabelMaker { self.label.font = font return self } public func setTextColor(to color: UIColor) -> UILabelMaker { self.label.textColor = color return self } public func setTextAlignment(to alignment: NSTextAlignment) -> UILabelMaker { self.label.textAlignment = alignment return self } public func setNumberOfLines(to number: Int) -> UILabelMaker { self.label.numberOfLines = number return self } public func setLineBreakMode(to mode: NSLineBreakMode) -> UILabelMaker { self.label.lineBreakMode = mode return self } }
  19. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } }
  20. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  21. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  22. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  23. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  24. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  25. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  26. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  27. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  28. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  29. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  30. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  31. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  32. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  33. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  34. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) -> UILabelMaker in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  35. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { (maker) in return maker .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  36. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { return $0 .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  37. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero, by: { $0 .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) })
  38. APIs in UILabelMaker public struct UILabelMaker { let label: UILabel

    } extension UILabel { public static func make(withFrame frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel.make(withFrame: .zero) { $0 .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) }
  39. ཧ૝ͳΠχγϟϥΠβʔ let label = UILabel(frame: .zero) { $0 .setFont(to: .systemFont(ofSize:

    20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) } // ੒Ռ෺ let label = UILabel.make(withFrame: .zero) { $0 .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) } ؔ਺໊௕͗͢
  40. Tricks in Initializers class SomeClass { var someInt: Int init(someInt:

    Int) { self.someInt = someInt } } let someClass = SomeClass() //Error: Missing arguments
  41. Tricks in Initializers class SomeClass { var someInt: Int init(someInt:

    Int) { self.someInt = someInt } } extension SomeClass { static func `init`() -> SomeClass { return SomeClass(someInt: 0) } } let someClass = SomeClass() //someClass.someInt == 0
  42. APIs in UILabelMaker public struct UILabelMaker { fileprivate let label:

    UILabel } extension UILabel { public static func `init`(frame: CGRect = .zero, by making: (UILabelMaker) -> UILabelMaker) -> UILabel { let label = UILabel(frame: frame) let maker = UILabelMaker(label: label) let resultMaker = making(maker) let resultLabel = resultMaker.label return resultLabel } } let label = UILabel(frame: .zero) { $0 .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) }
  43. ཧ૝ͳΠχγϟϥΠβʔ let label = UILabel(frame: .zero) { $0 .setFont(to: .systemFont(ofSize:

    20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) } // ੒Ռ෺ let label = UILabel(frame: .zero) { $0 .setFont(to: .systemFont(ofSize: 20)) .setTextAlignment(to: .center) .setTextColor(to: .blue) .setNumberOfLines(to: 1) } ׬શʹҰக$
  44. Կ͔ͷܕ͕ग़Δͨͼʹ XxxMaker ࡞ΔͷͩΔ͍ʂ public struct Maker<Product> { let product: Product

    } extension Maker where Product: UILabel { public func setFont(to font: UIFont) -> Maker public func setTextColor(to color: UIColor) -> Maker public func setTextAlignment(to alignment: NSTextAlignment) -> Maker public func setNumberOfLines(to number: Int) -> Maker public func setLineBreakMode(to mode: NSLineBreakMode) -> Maker } extension UILabel { public static func `init`(frame: CGRect = .zero, by making: (Maker<UILabel>) -> Maker<UILabel>) -> UILabel }
  45. Կ͔ͷܕ͕ग़Δͨͼʹ XxxMaker ࡞ΔͷͩΔ͍ʂ public struct Maker<Product> { let product: Product

    } extension Maker where Product: UILabel { public func setFont(to font: UIFont) -> Maker public func setTextColor(to color: UIColor) -> Maker public func setTextAlignment(to alignment: NSTextAlignment) -> Maker public func setNumberOfLines(to number: Int) -> Maker public func setLineBreakMode(to mode: NSLineBreakMode) -> Maker } extension UILabel { public static func `init`(frame: CGRect = .zero, by making: (Maker<UILabel>) -> Maker<UILabel>) -> UILabel } ܕ͝ͱͷઃఆϝιου͚ͩ
 ࡞Ε͹ྑ͍
  46. ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ public struct MakerType<Package> { let package: Package public init(_

    package: Package) { self.package = package } } public protocol MakerTypeCompatible { } extension MakerTypeCompatible { public typealias MKR = MakerType<Self> public var mkr: MKR { return MakerType(self) } }
  47. ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ public struct MakerType<Package> { let package: Package public init(_

    package: Package) } public protocol MakerTypeCompatible { } extension MakerTypeCompatible { public typealias MKR = MakerType<Self> public var mkr: MKR } extension UILabel: MakerTypeCompatible { } public extension MakerType where Package == UILabel { public static func `init`(frame: CGRect = .zero, by making: (Maker<UILabel>) -> Maker<UILabel>) -> UILabel { let label = UILabel(frame: frame) let maker = Maker(product: label) let resultMaker = making(maker) let resultLabel = resultMaker.product return resultLabel } }
  48. ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ public struct MakerType<Package> { let package: Package public init(_

    package: Package) } public protocol MakerTypeCompatible { } extension MakerTypeCompatible { public typealias MKR = MakerType<Self> public var mkr: MKR } extension UILabel: MakerTypeCompatible { } public extension MakerType where Package == UILabel { public static func `init`(frame: CGRect = .zero, by making: (Maker<UILabel>) -> Maker<UILabel>) -> UILabel } let label = UILabel.MKR(frame: .zero) { $0 .setNumberOfLines(to: 0) .setTextColor(to: .blue) }
  49. ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ public struct MakerType<Package> { let package: Package public init(_

    package: Package) } public protocol MakerTypeCompatible { } extension MakerTypeCompatible { public typealias MKR = MakerType<Self> public var mkr: MKR } extension UILabel: MakerTypeCompatible { } public extension MakerType where Package == UILabel { public static func `init`(frame: CGRect = .zero, by making: (Maker<UILabel>) -> Maker<UILabel>) -> UILabel } let label = UILabel.MKR(frame: .zero) { $0 .setNumberOfLines(to: 0) .setTextColor(to: .blue) }