I am try to predicate on the optional value and it always crash the application with following error.
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key q_id.' * First throw call stack:
Although there is variable define in the model but it is define like this
var q_id : Int!
If i convert this variable in unwrap it workings fine
var q_id = Int()
So is there any other way for predicate on optional value?
let Qid = dictData.objectForKey("q_id") as? String
let fQuesID : Int = Int(Qid!)!;
let predicate = NSPredicate(format: "SELF.q_id == %i",fQuesID)
let arrObj : NSArray = arrData.filteredArrayUsingPredicate(predicate) ;
//arrData.filter { predicate.evaluateWithObject($0) }
if(arrObj.count > 0)
{
let objPostModel : ViewPostModel = arrObj.firstObject as! ViewPostModel;
objPostModel.isPollExpired = 1; // 1 Means Poll Expired!
self.tblViewPost?.reloadData();
}
It is only happened in primitive optional types variable (int,float,etc ... )
Update: If you make primitive type unoptional then it is working fine