I have function 

```
func findObjectInArray(array: [AnyObject], field: String?, fieldValue: AnyObject, startFromTheBeginning: Bool, minIndexTemp: Int, maxIndexTemp: Int) -> AnyObject?

```

And there I have:

```
var minIndex = minIndexTemp
        var maxIndex = maxIndexTemp
        if (array.count == 0 || minIndex < 0 || maxIndex < 0) {
            return nil
        }
        if (minIndex > maxIndex) {
            let rem = minIndex;
            minIndex = maxIndex;
            maxIndex = rem;
        }
        if (maxIndex >= array.count) {
            maxIndex = array.count - 1;
        }
        let startIndex = startFromTheBeginning ? minIndex : maxIndex;
        let endIndex = startFromTheBeginning ? maxIndex : minIndex;

        for (var i = startIndex; (startFromTheBeginning ? i <= endIndex : i >= 0); (startFromTheBeginning ? i++ : i--)) {
            let object = array[i]
            var objectFieldValue: AnyObject? = nil
            if (field != nil) {
                print("test = ", (object as! SAd).adID)
                objectFieldValue = object.valueForKeyPath(field!)
            }

```

I logs before crash I see `test = 1` . So it means that `object` was converted to `SAd` and it has the field `adID`, but on the row `objectFieldValue = object.valueForKeyPath(field!)` application crashes with error:

```
 *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Project.SAd 0x12d731930> valueForUndefinedKey:]: this class is not key value coding-compliant for the key adID

```

Here is the class 

```
class SAd: NSObject {
    var adID: Int!
    var bloggerID: Int!
    var createdOn: NSDate!
    var duration: Int!
    var fav: Int!
    var price: Double!
    var text: String!
    var countries: [String]!
    var categories: [String]!
    var deleted: Bool!
}

```

**Actually, you can test the same behavio in your code very simply:**

create class:

```
class STest: NSObject {
    var idTest: Int?
    var strTest: String?
}

```

and in your AppDelegate file:

```
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let testObj1 = STest()
    testObj1.idTest = 1
    testObj1.strTest = "test"
    let objValue = testObj1 .valueForKeyPath("idTest")

    return true
}

```

you will see the crash at line `let objValue = testObj1 .valueForKeyPath("idTest")`

**but if you replace this line with `let objValue = testObj1 .valueForKeyPath("strTest")` it will work. So the problem is in Int value**