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
[AWS JAPAN 生成AIハッカソン] Dialog の紹介
yoshimi0227
0
150
Amazon FSx for NetApp ONTAPを利用するにあたっての要件整理と設計のポイント
non97
1
160
[JAWS-UG金沢支部×コンテナ支部合同企画]コンテナとは何か
furuton
3
260
いまならこう作りたい AWSコンテナ[本格]入門ハンズオン 〜2024年版 ハンズオンの構想〜
horsewin
9
2.1k
Aurora_BlueGreenDeploymentsやってみた
tsukasa_ishimaru
1
130
生成AIと知識グラフの相互利用に基づく文書解析
koujikozaki
1
140
Commitment vs Harrisonism - Keynote for Scrum Niseko 2024
miholovesq
6
1.1k
【若手エンジニア応援LT会】AWSで繋がり、共に成長! ~コミュニティ活動と新人教育への挑戦~
kazushi_ohata
0
180
「最高のチューニング」をしないために / hack@delta 24.10
fujiwara3
21
3.5k
チームを主語にしてみる / Making "Team" the Subject
ar_tama
4
310
【技術書典17】OpenFOAM(自宅で極める流体解析)2次元円柱まわりの流れ
kamakiri1225
0
220
いまさらのStorybook
ikumatadokoro
0
150
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
43
13k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
22k
Happy Clients
brianwarren
97
6.7k
Designing for humans not robots
tammielis
249
25k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Scaling GitHub
holman
458
140k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Building Your Own Lightsaber
phodgson
102
6.1k
Gamification - CAS2011
davidbonilla
80
5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
290
KATA
mclloyd
29
13k
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/