Created
October 13, 2013 17:10
-
-
Save vipulnsward/6964682 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(main)> price_greater_than_200 = NSPredicate.predicateWithFormat("price > 200") | |
=> #<NSComparisonPredicate:0x1293bc50> | |
(main)> products.filteredArrayUsingPredicate(price_greater_than_200) | |
=> [#<Product:0x9b4f780 @name="iPad Mini" @price=329 @launched_on=2012-11-02 00:00:00 +0530>, #<Product:0x9b4fac0 @name="MacBook Pro" @price=1699 @launched_on=2012-06-11 00:00:00 +0530>, #<Product:0x9b4fe00 @name="iMac" @price=1299 @launched_on=2012-11-02 00:00:00 +0530>] | |
(main)> price_greater_than_equal = NSPredicate.predicateWithFormat("price >= 1299") | |
=> #<NSComparisonPredicate:0x9b1b740> | |
(main)> products.filteredArrayUsingPredicate(price_greater_than_equal) | |
=> [#<Product:0x9b4fac0 @name="MacBook Pro" @price=1699 @launched_on=2012-06-11 00:00:00 +0530>, #<Product:0x9b4fe00 @name="iMac" @price=1299 @launched_on=2012-11-02 00:00:00 +0530>] | |
(main)>> price_between = NSPredicate.predicateWithFormat("price BETWEEN {100 , 2000}") | |
=> #<NSComparisonPredicate:0x1293f3e0> | |
(main)> products.filteredArrayUsingPredicate(price_between) | |
=> [#<Product:0x9b4ddb0 @name="iPhone 5" @price=199 @launched_on=2012-09-21 00:00:00 +0530>, #<Product:0x9b4f780 @name="iPad Mini" @price=329 @launched_on=2012-11-02 00:00:00 +0530>, #<Product:0x9b4fac0 @name="MacBook Pro" @price=1699 @launched_on=2012-06-11 00:00:00 +0530>, #<Product:0x9b4fe00 @name="iMac" @price=1299 @launched_on=2012-11-02 00:00:00 +0530>] | |
(main)> name_begins_with = NSPredicate.predicateWithFormat("name BEGINSWITH[cd] 'i'") | |
=> #<NSComparisonPredicate:0x1293f660> | |
(main)> products.filteredArrayUsingPredicate(name_begins_with) | |
=> [#<Product:0x9b4ddb0 @name="iPhone 5" @price=199 @launched_on=2012-09-21 00:00:00 +0530>, #<Product:0x9b4f780 @name="iPad Mini" @price=329 @launched_on=2012-11-02 00:00:00 +0530>, #<Product:0x9b4fe00 @name="iMac" @price=1299 @launched_on=2012-11-02 00:00:00 +0530>] | |
(main)> name_contains =NSPredicate.predicateWithFormat("name CONTAINS[cd] 'i'") | |
=> #<NSComparisonPredicate:0x9b19050> | |
(main)> products.filteredArrayUsingPredicate(name_contains) | |
=> [#<Product:0x9b4ddb0 @name="iPhone 5" @price=199 @launched_on=2012-09-21 00:00:00 +0530>, #<Product:0x9b4f780 @name="iPad Mini" @price=329 @launched_on=2012-11-02 00:00:00 +0530>, #<Product:0x9b4fe00 @name="iMac" @price=1299 @launched_on=2012-11-02 00:00:00 +0530>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment