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
신뢰할 수 있는 AI 검색 엔진을 만들기 위한 Liner의 여정
huffon
0
360
一休.comレストランにおけるRustの活用
kymmt90
3
580
Apple/Google/Amazonの決済システムの違いを踏まえた定期購読課金システムの構築 / abema-billing-system
cyberagentdevelopers
PRO
1
220
新卒1年目が挑む!生成AI × マルチエージェントで実現する次世代オンボーディング / operation-ai-onboarding
cyberagentdevelopers
PRO
1
170
事業者間調整の行間を読む 調整の具体事例
sugiim
0
1.5k
[JAWS-UG金沢支部×コンテナ支部合同企画]コンテナとは何か
furuton
3
260
チームを主語にしてみる / Making "Team" the Subject
ar_tama
4
310
現地でMeet Upをやる場合の注意点〜反省点を添えて〜
shotashiratori
0
530
Datachain会社紹介資料(2024年11月) / Company Deck
datachain
3
16k
Autify Company Deck
autifyhq
1
39k
顧客が本当に必要だったもの - パフォーマンス改善編 / Make what is needed
soudai
24
6.8k
Vueで Webコンポーネントを作って Reactで使う / 20241030-cloudsign-vuefes_after_night
bengo4com
4
2.5k
Featured
See All Featured
Six Lessons from altMBA
skipperchong
26
3.5k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
GraphQLの誤解/rethinking-graphql
sonatard
66
9.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Designing the Hi-DPI Web
ddemaree
280
34k
What's in a price? How to price your products and services
michaelherold
243
12k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Designing for Performance
lara
604
68k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
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/