Auto increment ID in Realm, Swift 3.0
<p>After a lot of troubles, i finally got my code converted to Swift 3.0.</p>

<p>But it seems like my incrementID function isn't working anymore?</p>

<p>Any suggestions how i can fix this?</p>

<p>My incrementID and primaryKey function as they look right now.</p>

<pre><code>override static func primaryKey() -&gt; String? {
    return "id"
}

func incrementID() -&gt; Int{
    let realm = try! Realm()
    let RetNext: NSArray = Array(realm.objects(Exercise.self).sorted(byProperty: "id")) as NSArray
    let last = RetNext.lastObject
    if RetNext.count &gt; 0 {
        let valor = (last as AnyObject).value(forKey: "id") as? Int
        return valor! + 1
    } else {
        return 1
    }
}
</code></pre>