             let realm = try Realm()
             let count = DBmethod().DBRecordCount(ShiftSystemDB)
             
-            for(var i = id; i < count; i++){
+            for i in id ..< count{
                 let nextrecord = realm.objects(ShiftSystemDB).filter("id = %@",i+1)[0]
                 
                 let newrecord = ShiftSystemDB()

        var tmparray: [ShiftSystemDB] = []
        
        //ソート後のレコード内容を作業用配列に入れる
        for(var i = 0; i < sortedresults.count; i++){
            let tmprecord = ShiftSystemDB()
            tmprecord.id = sortedresults[i].id
            tmprecord.name = sortedresults[i].name

        do{
            try realm.write({ () -> Void in
                realm.delete(nonsortedresults)
                for i in 0 ..< tmparray.count{
                    realm.add(tmparray[i], update: true)
                }
            })
