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
KVC Collection Operators
Search
Katsuma Tanaka
April 19, 2014
Technology
0
250
KVC Collection Operators
第55回Cocoa勉強会関西での発表に使用したスライドです。
Katsuma Tanaka
April 19, 2014
Tweet
Share
More Decks by Katsuma Tanaka
See All by Katsuma Tanaka
Plug-in Architectures in Cocoa
questbeat
1
640
Other Decks in Technology
See All in Technology
Introduction to Works of ML Engineer in LY Corporation
lycorp_recruit_jp
0
140
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.7k
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
120
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
OS 標準のデザインシステムを超えて - より柔軟な Flutter テーマ管理 | FlutterKaigi 2024
ronnnnn
0
220
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
420
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.5k
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
Featured
See All Featured
Making Projects Easy
brettharned
115
5.9k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Being A Developer After 40
akosma
87
590k
A designer walks into a library…
pauljervisheath
204
24k
Practical Orchestrator
shlominoach
186
10k
GitHub's CSS Performance
jonrohan
1030
460k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Agile that works and the tools we love
rasmusluckow
327
21k
Transcript
@questbeat KVC Collection Operators
http://github.com/questbeat/ KVCCollectionOperatorsExample
KVC Collection Operators
KVC Collection Operators
Key-Value Coding
Key-Value Coding • ΦϒδΣΫτͷϓϩύςΟʹ ؒతʹΞΫηε͢ΔͨΊͷΈ • Key (จࣈྻ)ΛͬͯϓϩύςΟΛࣝผ͢Δ [status valueForKey:@“text”];
! => @“Hi, friends!”
Key-Value Coding • KeyPath • υοτͰ۠ΒΕͨෳͷΩʔ͔Β ͳΔจࣈྻ [status valueForKeyPath: @“user.screen_name”];
! => @“questbeat”
KVC Collection Operators
KVC Collection Operators • ίϨΫγϣϯԋࢉࢠ • valueForKeyPath: Ͱ͑Δԋࢉࢠ • @
͔Β࢝·Δจࣈྻ • @count, @sum, @avg ͳͲ
KVC Collection Operators
[email protected]
ԋࢉͰ༻͢Δ ྻू߹ͷ KeyPath ԋࢉࢠ ԋࢉͰ༻͢Δ (ίϨΫγϣϯͷ
ཁૉͷ)ϓϩύςΟ ͷ KeyPath ԋࢉࢠΛͬͨ KeyPath ͷॻࣜ
KVC Collection Operators ྫ͑, Qiita ͷΫϥΠΞϯτΞϓϦͰ User @property NSArray *items;
Item @property NSUInteger stockCount;
KVC Collection Operators
[email protected]
͜ͷͱ͖, user ʹର͢ΔҎԼͷ KeyPath user.items
ͷ ֤ཁૉ͔ΒऔΓग़ͨ͠ stockCount ͷฏۉ Λද͢ (NSNumber)
KVC Collection Operators • 3छྨͷԋࢉࢠ • Simple Collection Operators (୯७ܕίϨΫγϣϯԋࢉࢠ)
• Object Operators (ΦϒδΣΫτԋࢉࢠ) • Array and Set Operators (ྻɾू߹ԋࢉࢠ)
Simple Collection Operators
@interface Fruit : NSObject ! @property NSString *name; @property double
price; @property NSDate *boughtAt; ! @end
NSArray *basket = @[ apple, banana, orange, grape ]; price
boughtAt Apple 100 2014/04/08 Banana 120 2014/03/18 Orange 200 2014/03/27 Grape 300 2014/04/14
Simple Collection Operators @count [basket valueForKeyPath:@“@count”]; ! => @(4) •
ίϨΫγϣϯͷཁૉΛฦ͢ (NSNumber) • ԋࢉࢠӈଆͷ KeyPath ແࢹ͞ΕΔ
Simple Collection Operators @sum [basket valueForKeyPath:@“@sum.price”]; ! => @(720) •
ϓϩύςΟͷ߹ܭΛฦ͢ (NSNumber) • Λ double ʹม͔ͯ͠Β߹ܭ͢Δ
Simple Collection Operators @avg [basket valueForKeyPath:@“@avg.price”]; ! => @(180) •
ϓϩύςΟͷฏۉΛฦ͢ (NSNumber) • Λ double ʹม͔ͯ͠Βฏۉ͢Δ
Simple Collection Operators @max [basket valueForKeyPath:@“@max.price”]; ! => @(300) •
ϓϩύςΟͷ͕࠷େͷͷΛฦ͢ • Λ compare: Ͱൺֱ͢Δ
Simple Collection Operators @max [basket valueForKeyPath:@“@max.boughtAt”]; ! => 2014-04-13 15:00:00
+0000 • ϓϩύςΟͷ͕࠷େͷͷΛฦ͢ • Λ compare: Ͱൺֱ͢Δ
Simple Collection Operators @min [basket valueForKeyPath:@“@min.price”]; ! => @(100) •
ϓϩύςΟͷ͕࠷খͷͷΛฦ͢ • Λ compare: Ͱൺֱ͢Δ
Simple Collection Operators ͜͜·Ͱͷ·ͱΊ • @count • @sum • @avg
• @max • @min
Object Operators
NSArray *basket = @[ apple, apple, banana, orange, grape ];
Object Operators @unionOfObjects [basket valueForKeyPath: @“@unionOfObjects.name”]; ! => @[ @“Apple”,
@“Apple”, @“Banana”, @“Orange, @“Grape” ] • ϓϩύςΟͷΛ·ͱΊͯ NSArray Ͱฦ͢ • ॏෳ͕͋ͬͯͦͷ··
Object Operators @distinctUnionOfObjects [basket valueForKeyPath: @“@distinctUnionOfObjects.name”]; ! => @[ @“Apple”,
@“Orange” @“Banana, @“Grape” ] • ϓϩύςΟͷΛ·ͱΊͯ NSArray Ͱฦ͢ • ॏෳΛऔΓআ͘
• @unionOfObjects • @distinctUnionOfObjects Object Operators ͜͜·Ͱͷ·ͱΊ
Array and Set Operators
NSArray *hogeStoreInventory = @[ apple, banana ]; ! NSArray *piyoStoreInventory
= @[ apple, orange ]; ! NSArray *inventories = @[ hogeStoreInventory, piyoStoreInventory ];
Array and Set Operators @unionOfArrays [inventories valueForKeyPath: @“@unionOfArrays.name”]; ! =>
@[ @“Apple”, @“Banana” @“Apple, @“Orange” ] • ίϨΫγϣϯʹؚ·ΕΔ֤ྻͷ ϓϩύςΟͷΛ·ͱΊͯ NSArray Ͱฦ͢
Array and Set Operators @distinctUnionOfArrays [inventories valueForKeyPath: @“@unionOfArrays.name”]; ! =>
@[ @“Apple”, @“Orange”, @“Banana” ] • ίϨΫγϣϯʹؚ·ΕΔ֤ྻͷ ϓϩύςΟͷΛ·ͱΊͯ NSArray Ͱฦ͢ • ॏෳΛऔΓআ͘
Array and Set Operators @distinctUnionOfSets • @distinctUnionOfArrays ͱಉ༷͕ͩ NSSet ΛؚΉ
NSSet ͕ର • ίϨΫγϣϯʹؚ·ΕΔ֤ू߹ͷ ϓϩύςΟͷΛ·ͱΊͯ NSSet Ͱฦ͢ • ॏෳΛऔΓআ͘
• @unionOfArrays • @distinctUnionOfArrays • @distinctUnionOfSets ͜͜·Ͱͷ·ͱΊ Array and Set
Operators
• Collection Operators • valueForKeyPath: Ͱ͑Δԋࢉࢠ • 3छྨͷԋࢉࢠ • Simple
Collection Operators • Object Operators • Array and Set Operators Summary
• ศརͬΆ͍͚Ͳ, ͏ʁ Summary
• Cocoa Bindings Ͱେ׆༂ʂ Summary
Thanks! • ຊͷαϯϓϧίʔυ • http://github.com/questbeat/ KVCCollectionOperatorsExample • ࢀߟ • ΩʔίʔσΟϯάϓϩάϥϛϯάΨΠυ
https://developer.apple.com/jp/devcenter/ios/ library/documentation/KeyValueCoding.pdf • KVC Collection Operators - NSHipster http://nshipster.com/kvc-collection-operators/