Upgrade to Pro — share decks privately, control downloads, hide ads and more …

KVC Collection Operators

KVC Collection Operators

第55回Cocoa勉強会関西での発表に使用したスライドです。

Katsuma Tanaka

April 19, 2014
Tweet

More Decks by Katsuma Tanaka

Other Decks in Technology

Transcript

  1. KVC Collection Operators [email protected] ͜ͷͱ͖, user ʹର͢ΔҎԼͷ KeyPath ͸ user.items

    ͷ ֤ཁૉ͔ΒऔΓग़ͨ͠ stockCount ͷฏۉ Λද͢ (NSNumber)
  2. KVC Collection Operators • 3छྨͷԋࢉࢠ • Simple Collection Operators
 (୯७ܕίϨΫγϣϯԋࢉࢠ)

    • Object Operators
 (ΦϒδΣΫτԋࢉࢠ) • Array and Set Operators
 (഑ྻɾू߹ԋࢉࢠ)
  3. 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
  4. Simple Collection Operators @count [basket valueForKeyPath:@“@count”]; ! => @(4) •

    ίϨΫγϣϯͷཁૉ਺Λฦ͢ (NSNumber) • ԋࢉࢠӈଆͷ KeyPath ͸ແࢹ͞ΕΔ
  5. Simple Collection Operators @sum [basket valueForKeyPath:@“@sum.price”]; ! => @(720) •

    ϓϩύςΟ஋ͷ߹ܭΛฦ͢ (NSNumber) • ஋Λ double ʹม׵͔ͯ͠Β߹ܭ͢Δ
  6. Simple Collection Operators @avg [basket valueForKeyPath:@“@avg.price”]; ! => @(180) •

    ϓϩύςΟ஋ͷฏۉ஋Λฦ͢ (NSNumber) • ஋Λ double ʹม׵͔ͯ͠Βฏۉ͢Δ
  7. Simple Collection Operators @max [basket valueForKeyPath:@“@max.price”]; ! => @(300) •

    ϓϩύςΟͷ஋͕࠷େͷ΋ͷΛฦ͢ • ஋Λ compare: Ͱൺֱ͢Δ
  8. Simple Collection Operators @max [basket valueForKeyPath:@“@max.boughtAt”]; ! => 2014-04-13 15:00:00

    +0000 • ϓϩύςΟͷ஋͕࠷େͷ΋ͷΛฦ͢ • ஋Λ compare: Ͱൺֱ͢Δ
  9. Simple Collection Operators @min [basket valueForKeyPath:@“@min.price”]; ! => @(100) •

    ϓϩύςΟͷ஋͕࠷খͷ΋ͷΛฦ͢ • ஋Λ compare: Ͱൺֱ͢Δ
  10. Object Operators @unionOfObjects [basket valueForKeyPath: @“@unionOfObjects.name”]; ! => @[ @“Apple”,

    @“Apple”, @“Banana”, @“Orange, @“Grape” ] • ϓϩύςΟͷ஋Λ·ͱΊͯ NSArray Ͱฦ͢ • ॏෳ͕͋ͬͯ΋ͦͷ··
  11. Object Operators @distinctUnionOfObjects [basket valueForKeyPath: @“@distinctUnionOfObjects.name”]; ! => @[ @“Apple”,

    @“Orange” @“Banana, @“Grape” ] • ϓϩύςΟͷ஋Λ·ͱΊͯ NSArray Ͱฦ͢ • ॏෳΛऔΓআ͘
  12. NSArray *hogeStoreInventory = @[ apple, banana ]; ! NSArray *piyoStoreInventory

    = @[ apple, orange ]; ! NSArray *inventories = @[ hogeStoreInventory, piyoStoreInventory ];
  13. Array and Set Operators @unionOfArrays [inventories valueForKeyPath: @“@unionOfArrays.name”]; ! =>

    @[ @“Apple”, @“Banana” @“Apple, @“Orange” ] • ίϨΫγϣϯʹؚ·ΕΔ֤഑ྻͷ
 ϓϩύςΟͷ஋Λ·ͱΊͯ NSArray Ͱฦ͢
  14. Array and Set Operators @distinctUnionOfArrays [inventories valueForKeyPath: @“@unionOfArrays.name”]; ! =>

    @[ @“Apple”, @“Orange”, @“Banana” ] • ίϨΫγϣϯʹؚ·ΕΔ֤഑ྻͷ
 ϓϩύςΟͷ஋Λ·ͱΊͯ NSArray Ͱฦ͢ • ॏෳΛऔΓআ͘
  15. Array and Set Operators @distinctUnionOfSets • @distinctUnionOfArrays ͱಉ༷͕ͩ
 NSSet ΛؚΉ

    NSSet ͕ର৅ • ίϨΫγϣϯʹؚ·ΕΔ֤ू߹ͷ
 ϓϩύςΟͷ஋Λ·ͱΊͯ NSSet Ͱฦ͢ • ॏෳΛऔΓআ͘
  16. • Collection Operators • valueForKeyPath: Ͱ࢖͑Δԋࢉࢠ • 3छྨͷԋࢉࢠ • Simple

    Collection Operators • Object Operators • Array and Set Operators Summary
  17. 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/