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
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
Symfony Mapper Component
soyuka
2
730
Recoilを剥がしている話
kirik
5
6.6k
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
230
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
930
CSC305 Lecture 25
javiergs
PRO
0
130
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Optimizing for Happiness
mojombo
376
70k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Agile that works and the tools we love
rasmusluckow
328
21k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
A Tale of Four Properties
chriscoyier
157
23k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Statistics for Hackers
jakevdp
796
220k
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ͱʹ͔͘࠷ߴ
͋Γ͕ͱ͏͍͟͝·ͨ͠