$30 off During Our Annual Pro Sale. View Details »

Code reviewing in iOS app development

Code reviewing in iOS app development

Code reviewing in iOS app development
@Kansai Mobile Conference #2

yashigani

May 20, 2015
Tweet

More Decks by yashigani

Other Decks in Programming

Transcript

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

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

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

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

    ίʔυϨϏϡʔͷ࿩ͱ͍͏͜ͱʹͳΓ·͢ɽ
  5. TUPSZCPBSEؔ࿈

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

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

  8. class ViewController: UIViewController { @IBOutlet weak var textView: UITextView! {

    didSet { textView.textContainerInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) } } }
  9. IBInspectableΛઃఆ͢Δ • ઃఆ͠ͳ͍ཧ༝͸ͳ͍ • ΠϚΠν࢖͍ʹ͔ͬͨ͘ΧελϜϏϡʔͷ࠶ར༻ੑ ͕ΊͬͪΌ্͕Γ·͢

  10. @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 } } }
  11. @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 } } }
  12. 7JFX$POUSPMMFSؔ࿈

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

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

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

  16. ?ΑΓ! • viewDidLoad΍prepareForSegueͰॳظԽ͢ΔΑ͏ ͳproperty͸Optionalʹ͕ͪ͠ • OptionalΑΓImplicitly Unwrapped Optionalͷ΄͏ ͕࢖͍΍͍͢ •

    Ͳ͏ͤແ͍ͱಈ͔ͳ͍Μ͔ͩΒૣ͘Ϋϥογϡͨ͠ ΄͏͕ಘ
  17. 4XJGUؔ࿈

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

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

    ྫ͑͹section headerͷλΠτϧͱ͔ • Associated Values΋ߟྀ͢Δ
  20. lazyͰOptionalΛ֎͢ • ࣗ෼ͷproperty Aʹґଘ͢Δproperty Bͷ࿩ • B͕ඞཁͳͱ͖ʹ͸A͸ଘࡏ͢Δͱ͖ɼBΛlazyʹ͢ Δ͜ͱͰOptionalΛ֎͢͜ͱ͕Ͱ͖Δ

  21. 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) } }
  22. class BookmarkManager { let manager: UserManager init(_ manager: UserManager) {

    self.manager = manager } } class ViewController: UIViewController { var userManager: UserManager! lazy var bookmarkManager: BookmarkManager = BookmarkManager(self.userManager) }
  23. ςετͰ͸!Λ࢖Θͳ͍ • ςετ͕ࣦഊ͢ΔΜ͡Όͳͯ͘མͪΔ • CIͰٽ͘ • ࠷ѱͷঢ়ଶ • ஋͕औಘͰ͖Δ͸ͣͰ΋Optional Chainͱ͔҆શͳ

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

    "...")
  25. let bookmark: Bookmark = ... XCTAssertNotNil(bookmark.title, "...") XCTAssertEqual(bookmark.title ?? "",

    "ؔ੢ϞόΠϧΞϓϦݚڀձ#2", "...")
  26. ·ͱΊ

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

  28. ͋Γ͕ͱ͏͍͟͝·ͨ͠