Waleed Rahman Waleed Rahman - 3 months ago 118
iOS Question

Swift - Operator == Cannot be applied to two Int operands

This is freaking me out and is super-annoying. I've had similar issues before but don't know how I fixed it.

So, I have this condition

for jfa:Dictionary<String, AnyObject> in jfaDict {
if Int(jfa[JobType.JobNoKey]) == jobNo
{
//Some stuff to do here
}
}


JobType.JobNoKey is a string while jobNo is an Int

And I'm getting the following error:


Binary operator '==' cannot be applied to two Int operands


What does this mean?

Answer

You need to unwrap jfa[] first:

if jfa[JobType.JobNoKey] as! Int == jobNo {
    //Some stuff to do here
}