Posts

Showing posts from October, 2017

NSPredicate with Swift.

Image
With NSPredicate in Objective-C it was easy to filter the NSARRAY and get the desired results ex: In the Array for Food items, if we want to filter results which has food item's having 'ice' in the foodName. And with Swift it's even getting simpler , with the use of filter method. With recent version of Swift, the use of NSPredicate is discouraged. Currently with Swift 4.0 the following code fails, but it could work in earlier versions of swift. Let me explain it to you with simple NSPredicate used along with Swift.   let foodArray = [ Food (foodId: "1" , foodName: "Pizza" , spiceLevel: 5 ),                          Food (foodId: "2" , foodName: "Pasta" , spiceLevel: 4 ),                          Food (foodId: "3" , foodName: "IceCream" , spiceLevel: 0 ),                          Food (foodId: "4" , foodName: "Yogurt IceCream" , spiceLevel: 0 )]