Slide 1

Slide 1 text

J04ΞϓϦͷίʔυϨϏϡʔ Ͱ࠷ۙؾʹͳΔͱ͜Ζ @yashigani ؔ੢ϞόΠϧΞϓϦݚڀձ#2

Slide 2

Slide 2 text

yashigani id:yashigani_w @yashigani Mobile Application Engineer http://yashigani.hatenablog.com Hatena

Slide 3

Slide 3 text

https://flic.kr/p/b3j2n2 ίʔυϨϏϡʔ ͯ͠·͔͢ʁ

Slide 4

Slide 4 text

ͳΜ͔ωλ୳ͯͨ͠ΜͰ͚͢Ͳಛʹ͜Εͬ ͯ΋ͷ͕ແͯ͘ɼ͋ΕʁίʔυϨϏϡʔͱ ͔ΊͬͪΌҙࣝߴͦ͏Ͱ͍͍Μ͡ΌͶʁͬ ͓ͯ΋ͬͯ·ͱΊͯΈͨΜͰ͢Αɽͦͨ͠ ΒίʔυϨϏϡʔͷ؍఺ͬͯΑ͘ߟ͑ͨΒ ΞϓϦέʔγϣϯΛઃܭ͢Δͱ͖ʹؾΛ ͚ͭΔ΂͖ϙΠϯτ·ͱΊΈ͍ͨͳײ͡ ͳΜͰ͢ΑɽͳΜͰͦ͏͍͏͜ͱ࿩͢ΜͰ ͚͢ͲɼίʔυϨϏϡʔͬͯ୊͓͍ͯͨ͠ ΄͏͕ͳΜ͔͋Γ͕ͨΈ͕ߴ͍ΜͰࠓ೔͸ ίʔυϨϏϡʔͷ࿩ͱ͍͏͜ͱʹͳΓ·͢ɽ

Slide 5

Slide 5 text

TUPSZCPBSEؔ࿈

Slide 6

Slide 6 text

͜ΕstoryboardͰͰ͖·ͤΜ͔ʁ • ࡉ͔͍viewͷઃఆ΋Ͱ͖Δ͚ͩstoryboardͰ׬݁͞ ͤͨ΄͏ָ͕ • ෼ࢄ͢Δͱ͋ͱͰ௚͠ʹ͍͘ • ϨΠΞ΢τͷίʔυ΋جຊ͸ॻ͔ͳ͍ • (AutoLayoutͷϨϏϡʔ͸ࠜੑͰ΍Δ)

Slide 7

Slide 7 text

storyboardͰઃఆͰ͖ͳ͍஋ • viewDidLoadͱ͔awakeFromNibͰೖΕΔͷ͸! • propertyͷdidSetΛ࢖ͬͨ΄͏͕៉ྷ • Objective-C?ૣ͘غͯͯ͘Ε

Slide 8

Slide 8 text

class ViewController: UIViewController { @IBOutlet weak var textView: UITextView! { didSet { textView.textContainerInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) } } }

Slide 9

Slide 9 text

IBInspectableΛઃఆ͢Δ • ઃఆ͠ͳ͍ཧ༝͸ͳ͍ • ΠϚΠν࢖͍ʹ͔ͬͨ͘ΧελϜϏϡʔͷ࠶ར༻ੑ ͕ΊͬͪΌ্͕Γ·͢

Slide 10

Slide 10 text

@IBDesignable class BorderedLabel: UILabel { @IBInspectable var borderColor: UIColor? { get { return UIColor(CGColor: self.layer.borderColor) } set { self.layer.borderColor = newValue?.CGColor ?? nil } } @IBInspectable var borderWidth: CGFloat = 1.0 { didSet { layer.borderWidth = borderWidth } } @IBInspectable var cornerRadius: CGFloat = 0.0 { didSet { layer.cornerRadius = cornerRadius layer.masksToBounds = cornerRadius > 0.0 } } }

Slide 11

Slide 11 text

@IBDesignable class BorderedLabel: UILabel { @IBInspectable var borderColor: UIColor? { get { return UIColor(CGColor: self.layer.borderColor) } set { self.layer.borderColor = newValue?.CGColor ?? nil } } @IBInspectable var borderWidth: CGFloat = 1.0 { didSet { layer.borderWidth = borderWidth } } @IBInspectable var cornerRadius: CGFloat = 0.0 { didSet { layer.cornerRadius = cornerRadius layer.masksToBounds = cornerRadius > 0.0 } } }

Slide 12

Slide 12 text

7JFX$POUSPMMFSؔ࿈

Slide 13

Slide 13 text

͜ͷpropertyݮΒͤ·ͤΜ͔ʁ • stored property͸ঢ়ଶͳͷͰͰ͖Δ͚ͩݮΒͨ͠΄ ͏͕Α͍ • computed property͸ผ • closureͰΩϟϓνϟ͢Δͱ͔ͰͳΜͱ͔Ͱ͖ͳ͍͔

Slide 14

Slide 14 text

UITableViewDataSource ෼ׂͰ͖·ͤΜ͔ʁ • UITableViewDataSource͸෼ׂ͠΍͍͢ͷͰૣΊʹ ෼ׂ͓ͯ͘͠ • NSObject͸storyboard͔Β஫ೖͰ͖Δ

Slide 15

Slide 15 text

UITableViewDataSource ෼ׂͰ͖·ͤΜ͔ʁ • UITableViewDataSource͸෼ׂ͠΍͍͢ͷͰૣΊʹ ෼ׂ͓ͯ͘͠ • NSObject͸storyboard͔Β஫ೖͰ͖Δ

Slide 16

Slide 16 text

?ΑΓ! • viewDidLoad΍prepareForSegueͰॳظԽ͢ΔΑ͏ ͳproperty͸Optionalʹ͕ͪ͠ • OptionalΑΓImplicitly Unwrapped Optionalͷ΄͏ ͕࢖͍΍͍͢ • Ͳ͏ͤແ͍ͱಈ͔ͳ͍Μ͔ͩΒૣ͘Ϋϥογϡͨ͠ ΄͏͕ಘ

Slide 17

Slide 17 text

4XJGUؔ࿈

Slide 18

Slide 18 text

computed property࢖͑·ͤΜ͔ʁ • ఆ਺΍ͦͷΦϒδΣΫτͷঢ়ଶ͔Βࢉग़Ͱ͖Δ஋Λ ฦ͢ϝιου͸computed propertyʹ • υϝΠϯΛด͡ࠐΊΒΕΔ • ͋ͱ()͕͍Βͳ͘ͳΔͷͰྑ͍

Slide 19

Slide 19 text

enum࢖͑·ͤΜ͔ʁ • ϓϦϛςΟϒͳ஋΍ઐ༻ͷΦϒδΣΫτͰঢ়ଶΛ
 ؅ཧ͍͍ͯ͠ͷ͸খֶੜ·Ͱ • UITableViewͷsectionͱ͔(Raw ValuesΛ࢖͏ͱΑ͍) • enumʹด͡ࠐΊΔ • ྫ͑͹section headerͷλΠτϧͱ͔ • Associated Values΋ߟྀ͢Δ

Slide 20

Slide 20 text

lazyͰOptionalΛ֎͢ • ࣗ෼ͷproperty Aʹґଘ͢Δproperty Bͷ࿩ • B͕ඞཁͳͱ͖ʹ͸A͸ଘࡏ͢Δͱ͖ɼBΛlazyʹ͢ Δ͜ͱͰOptionalΛ֎͢͜ͱ͕Ͱ͖Δ

Slide 21

Slide 21 text

class BookmarkManager { let manager: UserManager init(_ manager: UserManager) { self.manager = manager } } class ViewController: UIViewController { var userManager: UserManager! var bookmarkManager: BookmarkManager! override func viewDidLoad() { bookmarkManager = BookmarkManager(userManager) } }

Slide 22

Slide 22 text

class BookmarkManager { let manager: UserManager init(_ manager: UserManager) { self.manager = manager } } class ViewController: UIViewController { var userManager: UserManager! lazy var bookmarkManager: BookmarkManager = BookmarkManager(self.userManager) }

Slide 23

Slide 23 text

ςετͰ͸!Λ࢖Θͳ͍ • ςετ͕ࣦഊ͢ΔΜ͡Όͳͯ͘མͪΔ • CIͰٽ͘ • ࠷ѱͷঢ়ଶ • ஋͕औಘͰ͖Δ͸ͣͰ΋Optional Chainͱ͔҆શͳ खஈΛ࢖͏

Slide 24

Slide 24 text

let bookmark: Bookmark = ... XCTAssertNotNil(bookmark.title, "...") XCTAssertEqual(bookmark.title!, "ؔ ੢ϞόΠϧΞϓϦݚڀձ#2", "...")

Slide 25

Slide 25 text

let bookmark: Bookmark = ... XCTAssertNotNil(bookmark.title, "...") XCTAssertEqual(bookmark.title ?? "", "ؔ੢ϞόΠϧΞϓϦݚڀձ#2", "...")

Slide 26

Slide 26 text

·ͱΊ

Slide 27

Slide 27 text

• storyboard࢖͍౗ͯ͠΄͍͠ • View Controller͸ͱʹ͔͘ଠΒͳ͍Α͏ʹ͢Δ • Swift͸ͱʹ͔͘࠷ߴ

Slide 28

Slide 28 text

͋Γ͕ͱ͏͍͟͝·ͨ͠