Slide 1

Slide 1 text

ϞμϯͳΠχγϟϥΠβ for αϙʔλʔζCoLab

Slide 2

Slide 2 text

override init() { super.init() emplyedBy = "MAGES. 5pb. Game div" job = "iOS Developer" twitter = "@lovee" qiita = "@lovee" github = "el-hoshino" additionalInfo = "͍ͨͩ·ઈࢍస৬׆ಈதʘ(^o^)ʗ" class Speaker: Developer { } }

Slide 3

Slide 3 text

ΠχγϟϥΠβʔɺ ࢖ͬͯ·͔͢ʁ

Slide 4

Slide 4 text

ҰൠతͳΠχγϟϥΠβʔ ‣ Int("10") ‣ CGPoint(x: 10, y: 20) ‣ UILabel(frame: .zero) ‣ etc…

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

͜ΜͳΠχγϟϥΠζɺͨ͜͠ͱͳ͍͔ʁ 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 // ...

Slide 8

Slide 8 text

͜ΜͳΠχγϟϥΠζɺͨ͜͠ͱͳ͍͔ʁ 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 // ... ม਺໊ ؒҧ͑ͨ
 !

Slide 9

Slide 9 text

ΠχγϟϥΠζͱ ॳظઃఆΛ Ұ౓Ͱ΍Γ͍ͨʂ

Slide 10

Slide 10 text

໨ඪ ‣ Ұ౓Ͱੜ੒ͱઃఆΛऴΘΒͤΔ ‣ ಉ͡Ωʔϫʔυ͸ 2 ճ΋࢖Θͳ͍ ‣ IDEʢXcodeʣͷิ׬Λ࠷େݶʹར༻

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

"ੜ੒࣌ʹ ϝιουνΣʔϯΛ ࢖͍͍͕ͨɺ 
 ੜ੒͞ΕͨΦϒδΣΫτ͸ ϝιουνΣʔϯΛ ࢖͑ͯཉ͘͠ͳ͍

Slide 18

Slide 18 text

ੜ੒࣌ʹ͚ͩ࢖͏ܕΛ
 ࡞ͬͯ͠·͑͹͍͍#

Slide 19

Slide 19 text

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 }

Slide 20

Slide 20 text

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 } ʗਓ◕ ‿‿ ◕人ʘϫέΨϫΧϥφΠϤ

Slide 21

Slide 21 text

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 ͱͯ͠౉͍ͯͩ͘͠͞

Slide 22

Slide 22 text

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 Λ
 ग़ྗ͢Δϝιου͕ඞཁ

Slide 23

Slide 23 text

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 ΛϓϩύςΟʔͱͯ͠
 อ࣋͢Δඞཁ͕͋Δ

Slide 24

Slide 24 text

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 }

Slide 25

Slide 25 text

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 } }

Slide 26

Slide 26 text

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 } }

Slide 27

Slide 27 text

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) })

Slide 28

Slide 28 text

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) })

Slide 29

Slide 29 text

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) })

Slide 30

Slide 30 text

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) })

Slide 31

Slide 31 text

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) })

Slide 32

Slide 32 text

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) })

Slide 33

Slide 33 text

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) })

Slide 34

Slide 34 text

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) })

Slide 35

Slide 35 text

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) })

Slide 36

Slide 36 text

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) })

Slide 37

Slide 37 text

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) })

Slide 38

Slide 38 text

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) })

Slide 39

Slide 39 text

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) })

Slide 40

Slide 40 text

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) })

Slide 41

Slide 41 text

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) })

Slide 42

Slide 42 text

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) })

Slide 43

Slide 43 text

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) })

Slide 44

Slide 44 text

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) })

Slide 45

Slide 45 text

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) }

Slide 46

Slide 46 text

ཧ૝ͳΠχγϟϥΠβʔ 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) } ؔ਺໊௕͗͢

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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) }

Slide 50

Slide 50 text

ཧ૝ͳΠχγϟϥΠβʔ 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) } ׬શʹҰக$

Slide 51

Slide 51 text

ΧΠθϯ

Slide 52

Slide 52 text

ΧΠθϯ ‣ Կ͔ͷܕ͕ग़Δͨͼʹ XxxMaker ࡞ΔͷͩΔ͍ʂ ‣ ΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ ‣ ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ

Slide 53

Slide 53 text

Կ͔ͷܕ͕ग़Δͨͼʹ XxxMaker ࡞ΔͷͩΔ͍ʂ public struct Maker { 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) -> Maker) -> UILabel }

Slide 54

Slide 54 text

Կ͔ͷܕ͕ग़Δͨͼʹ XxxMaker ࡞ΔͷͩΔ͍ʂ public struct Maker { 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) -> Maker) -> UILabel } ܕ͝ͱͷઃఆϝιου͚ͩ
 ࡞Ε͹ྑ͍

Slide 55

Slide 55 text

ΧΠθϯ ‣ Կ͔ͷܕ͕ग़Δͨͼʹ XxxMaker ࡞ΔͷͩΔ͍ʂ ‣ ΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ ‣ ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ

Slide 56

Slide 56 text

΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ Framework Λ
 ࡞Δฤ

Slide 57

Slide 57 text

΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ

Slide 58

Slide 58 text

΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ

Slide 59

Slide 59 text

΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ Framework Λ
 ࢖͏ฤ

Slide 60

Slide 60 text

΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ

Slide 61

Slide 61 text

΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ

Slide 62

Slide 62 text

΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ

Slide 63

Slide 63 text

΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ https://speakerdeck.com/lovee/carthage-woshi-tutafei-opunnashe-nei-kai-fa ؔ࿈ςʔϚɿ
 ࣗ࡞ Framework Λ Carthage ʹରԠ͢Δ

Slide 64

Slide 64 text

ΧΠθϯ ‣ Կ͔ͷܕ͕ग़Δͨͼʹ XxxMaker ࡞ΔͷͩΔ͍ʂ ‣ ΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ ‣ ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ

Slide 65

Slide 65 text

ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ Targeted Extensions

Slide 66

Slide 66 text

ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ http://tech.vasily.jp/entry/swift_modern_extensions

Slide 67

Slide 67 text

ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ http://tech.vasily.jp/entry/swift_modern_extensions

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

ΧΠθϯ ‣ Կ͔ͷܕ͕ग़Δͨͼʹ XxxMaker ࡞ΔͷͩΔ͍ʂ ‣ ΋ͬͱͨ͘͞ΜͷϓϩδΣΫτͰڞ༗ͯ͠࢖͍͍ͨʂ ‣ ϑϨʔϜϫʔΫͰͷϝιουͷ໊લিಥΛճආ͍ͨ͠ʂ

Slide 73

Slide 73 text

DEMO