Code reviewing in iOS app development
by
yashigani
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
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ׂ͍͢͠ͷͰૣΊʹ ׂ͓ͯ͘͠ • NSObjectstoryboard͔ΒೖͰ͖Δ
Slide 15
Slide 15 text
UITableViewDataSource ׂͰ͖·ͤΜ͔ʁ • UITableViewDataSourceׂ͍͢͠ͷͰૣΊʹ ׂ͓ͯ͘͠ • NSObjectstoryboard͔ΒೖͰ͖Δ
Slide 16
Slide 16 text
?ΑΓ! • viewDidLoadprepareForSegueͰॳظԽ͢ΔΑ͏ ͳpropertyOptionalʹ͕ͪ͠ • 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
͋Γ͕ͱ͏͍͟͝·ͨ͠