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
OCI技術資料 : ファイル・ストレージ 概要
ocise
3
12k
Formal Development of Operating Systems in Rust
riru
1
380
実践! ソフトウェアエンジニアリングの価値の計測 ── Effort、Output、Outcome、Impact
nomuson
0
1.4k
#TRG24 / David Cuartielles / Post Open Source
tarugoconf
0
430
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
3
1.6k
30分でわかる「リスクから学ぶKubernetesコンテナセキュリティ」/30min-k8s-container-sec
mochizuki875
2
120
Oracle Base Database Service:サービス概要のご紹介
oracle4engineer
PRO
1
16k
20241220_S3 tablesの使い方を検証してみた
handy
4
870
Unlearn Product Development - Unleashed Edition
lemiorhan
PRO
2
170
シフトライトなテスト活動を適切に行うことで、無理な開発をせず、過剰にテストせず、顧客をビックリさせないプロダクトを作り上げているお話 #RSGT2025 / Shift Right
nihonbuson
3
1.6k
AWS re:Invent 2024 ふりかえり勉強会
yhana
0
700
[JAWS-UG新潟#20] re:Invent2024 -CloudOperationsアップデートについて-
shintaro_fukatsu
0
150
Featured
See All Featured
Embracing the Ebb and Flow
colly
84
4.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Mobile First: as difficult as doing things right
swwweet
222
9k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Automating Front-end Workflow
addyosmani
1366
200k
Gamification - CAS2011
davidbonilla
80
5.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
RailsConf 2023
tenderlove
29
960
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Fireside Chat
paigeccino
34
3.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
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/