Joseluis Joseluis - 5 months ago 20
Swift Question

Swift 2 Using Predicate can't get any result on my filter

What am I doing wrong ?

import UIKit
var values:NSMutableArray = []
let url = NSURL(string: "URL") // PHP JSON Result
let data = NSData(contentsOfURL: url!)
values = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSMutableArray

var searchtext = "ROYAL"

let resultPredicate = NSPredicate(format: "SELF contains[cd] %@", searchtext)
let filteredCars = values.filteredArrayUsingPredicate(resultPredicate)

Answer

Change your code like this

let resultPredicate = NSPredicate(format: "SELF.Vendor contains[cd] %@ OR SELF.vendor contains[cd] %@ OR SELF.email contains[cd] %@", searchtext, searchtext, searchtext)
let filteredCars = values.filteredArrayUsingPredicate(resultPredicate)

You need to add Key in which you want to filter the text.
Hope this will help you.

Comments