Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Code reviewing in iOS app development
Search
yashigani
May 20, 2015
Programming
9
4.4k
Code reviewing in iOS app development
Code reviewing in iOS app development
@Kansai Mobile Conference #2
yashigani
May 20, 2015
Tweet
Share
More Decks by yashigani
See All by yashigani
Hatena Engineer Seminar #10
yashigani
0
2.2k
Dependency Injection in iOS Apps
yashigani
2
460
Multiple layout with UITableViewCell
yashigani
1
3.4k
Lazy stored property
yashigani
3
2.1k
Useful 3 techniques developing in iOS Apps
yashigani
0
1.5k
Introduction to WebKitPlus
yashigani
2
2.3k
Types in Swift
yashigani
5
2.3k
Swift with apps by Hatena
yashigani
13
29k
What's new WebKit.framework
yashigani
2
1.4k
Other Decks in Programming
See All in Programming
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Remix on Hono on Cloudflare Workers
yusukebe
1
290
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
役立つログに取り組もう
irof
28
9.6k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
CSC509 Lecture 11
javiergs
PRO
0
180
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Better Code Design in PHP
afilina
PRO
0
130
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
cmp.Or に感動した
otakakot
2
150
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Docker and Python
trallard
40
3.1k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
A Tale of Four Properties
chriscoyier
156
23k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
Bash Introduction
62gerente
608
210k
Transcript
J04ΞϓϦͷίʔυϨϏϡʔ Ͱ࠷ۙؾʹͳΔͱ͜Ζ @yashigani ؔϞόΠϧΞϓϦݚڀձ#2
yashigani id:yashigani_w @yashigani Mobile Application Engineer http://yashigani.hatenablog.com Hatena
https://flic.kr/p/b3j2n2 ίʔυϨϏϡʔ ͯ͠·͔͢ʁ
ͳΜ͔ωλ୳ͯͨ͠ΜͰ͚͢Ͳಛʹ͜Εͬ ͯͷ͕ແͯ͘ɼ͋ΕʁίʔυϨϏϡʔͱ ͔ΊͬͪΌҙࣝߴͦ͏Ͱ͍͍Μ͡ΌͶʁͬ ͓ͯͬͯ·ͱΊͯΈͨΜͰ͢Αɽͦͨ͠ ΒίʔυϨϏϡʔͷ؍ͬͯΑ͘ߟ͑ͨΒ ΞϓϦέʔγϣϯΛઃܭ͢Δͱ͖ʹؾΛ ͚ͭΔ͖ϙΠϯτ·ͱΊΈ͍ͨͳײ͡ ͳΜͰ͢ΑɽͳΜͰͦ͏͍͏͜ͱ͢ΜͰ ͚͢ͲɼίʔυϨϏϡʔ͓͍ͬͯͯͨ͠ ΄͏͕ͳΜ͔͋Γ͕ͨΈ͕ߴ͍ΜͰࠓ
ίʔυϨϏϡʔͷͱ͍͏͜ͱʹͳΓ·͢ɽ
TUPSZCPBSEؔ࿈
͜ΕstoryboardͰͰ͖·ͤΜ͔ʁ • ࡉ͔͍viewͷઃఆͰ͖Δ͚ͩstoryboardͰ݁͞ ͤͨ΄͏ָ͕ • ࢄ͢Δͱ͋ͱͰ͠ʹ͍͘ • ϨΠΞτͷίʔυجຊॻ͔ͳ͍ • (AutoLayoutͷϨϏϡʔࠜੑͰΔ)
storyboardͰઃఆͰ͖ͳ͍ • viewDidLoadͱ͔awakeFromNibͰೖΕΔͷ! • propertyͷdidSetΛͬͨ΄͏͕៉ྷ • Objective-C?ૣ͘غͯͯ͘Ε
class ViewController: UIViewController { @IBOutlet weak var textView: UITextView! {
didSet { textView.textContainerInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) } } }
IBInspectableΛઃఆ͢Δ • ઃఆ͠ͳ͍ཧ༝ͳ͍ • ΠϚΠν͍ʹ͔ͬͨ͘ΧελϜϏϡʔͷ࠶ར༻ੑ ͕ΊͬͪΌ্͕Γ·͢
@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 } } }
@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 } } }
7JFX$POUSPMMFSؔ࿈
͜ͷpropertyݮΒͤ·ͤΜ͔ʁ • stored propertyঢ়ଶͳͷͰͰ͖Δ͚ͩݮΒͨ͠΄ ͏͕Α͍ • computed propertyผ • closureͰΩϟϓνϟ͢Δͱ͔ͰͳΜͱ͔Ͱ͖ͳ͍͔
UITableViewDataSource ׂͰ͖·ͤΜ͔ʁ • UITableViewDataSourceׂ͍͢͠ͷͰૣΊʹ ׂ͓ͯ͘͠ • NSObjectstoryboard͔ΒೖͰ͖Δ
UITableViewDataSource ׂͰ͖·ͤΜ͔ʁ • UITableViewDataSourceׂ͍͢͠ͷͰૣΊʹ ׂ͓ͯ͘͠ • NSObjectstoryboard͔ΒೖͰ͖Δ
?ΑΓ! • viewDidLoadprepareForSegueͰॳظԽ͢ΔΑ͏ ͳpropertyOptionalʹ͕ͪ͠ • OptionalΑΓImplicitly Unwrapped Optionalͷ΄͏ ͕͍͍͢ •
Ͳ͏ͤແ͍ͱಈ͔ͳ͍Μ͔ͩΒૣ͘Ϋϥογϡͨ͠ ΄͏͕ಘ
4XJGUؔ࿈
computed property͑·ͤΜ͔ʁ • ఆͦͷΦϒδΣΫτͷঢ়ଶ͔Βࢉग़Ͱ͖ΔΛ ฦ͢ϝιουcomputed propertyʹ • υϝΠϯΛด͡ࠐΊΒΕΔ • ͋ͱ()͕͍Βͳ͘ͳΔͷͰྑ͍
enum͑·ͤΜ͔ʁ • ϓϦϛςΟϒͳઐ༻ͷΦϒδΣΫτͰঢ়ଶΛ ཧ͍͍ͯ͠ͷখֶੜ·Ͱ • UITableViewͷsectionͱ͔(Raw ValuesΛ͏ͱΑ͍) • enumʹด͡ࠐΊΔ •
ྫ͑section headerͷλΠτϧͱ͔ • Associated Valuesߟྀ͢Δ
lazyͰOptionalΛ֎͢ • ࣗͷproperty Aʹґଘ͢Δproperty Bͷ • B͕ඞཁͳͱ͖ʹAଘࡏ͢Δͱ͖ɼBΛlazyʹ͢ Δ͜ͱͰOptionalΛ֎͢͜ͱ͕Ͱ͖Δ
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) } }
class BookmarkManager { let manager: UserManager init(_ manager: UserManager) {
self.manager = manager } } class ViewController: UIViewController { var userManager: UserManager! lazy var bookmarkManager: BookmarkManager = BookmarkManager(self.userManager) }
ςετͰ!ΛΘͳ͍ • ςετ͕ࣦഊ͢ΔΜ͡Όͳͯ͘མͪΔ • CIͰٽ͘ • ࠷ѱͷঢ়ଶ • ͕औಘͰ͖ΔͣͰOptional Chainͱ͔҆શͳ
खஈΛ͏
let bookmark: Bookmark = ... XCTAssertNotNil(bookmark.title, "...") XCTAssertEqual(bookmark.title!, "ؔ ϞόΠϧΞϓϦݚڀձ#2",
"...")
let bookmark: Bookmark = ... XCTAssertNotNil(bookmark.title, "...") XCTAssertEqual(bookmark.title ?? "",
"ؔϞόΠϧΞϓϦݚڀձ#2", "...")
·ͱΊ
• storyboard͍ͯ͠΄͍͠ • View Controllerͱʹ͔͘ଠΒͳ͍Α͏ʹ͢Δ • Swiftͱʹ͔͘࠷ߴ
͋Γ͕ͱ͏͍͟͝·ͨ͠