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
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
6
1.5k
React Routerで実現する型安全なSPAルーティング
sansantech
PRO
4
890
ZOZOTOWN の推薦における KPI モニタリング/KPI monitoring for ZOZOTOWN recommendations
rayuron
1
910
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
370
デジタルアイデンティティ技術 認可・ID連携・認証 応用 / 20250114-OIDF-J-EduWG-TechSWG
oidfj
2
270
知っててうれしい HTTP Cookie を使ったセッション管理について
greendrop
1
110
.NET 9 のパフォーマンス改善
nenonaninu
0
2.2k
Bring Your Own Container: When Containers Turn the Key to EDR Bypass/byoc-avtokyo2024
tkmru
0
440
Fabric 移行時の躓きポイントと対応策
ohata_ds
1
130
サーバーなしでWordPress運用、できますよ。
sogaoh
PRO
0
170
シフトライトなテスト活動を適切に行うことで、無理な開発をせず、過剰にテストせず、顧客をビックリさせないプロダクトを作り上げているお話 #RSGT2025 / Shift Right
nihonbuson
3
1.6k
rootful・rootless・privilegedコンテナの違い/rootful_rootless_privileged_container_difference
moz_sec_
0
110
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
340
4 Signs Your Business is Dying
shpigford
182
21k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Building an army of robots
kneath
302
44k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
The Language of Interfaces
destraynor
155
24k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Mobile First: as difficult as doing things right
swwweet
222
9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
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/