Terminating app due to uncaught exception 'NSRangeException', reason: '*** _oset_getObjectsRange: range {16, 16} extends beyond bounds [0 .. 29]' coredata delete

 Problem:

While delete the coredata object the below error came.

"Terminating app due to uncaught exception 'NSRangeException', reason: '*** _oset_getObjectsRange: range {16, 16} extends beyond bounds [0 .. 29]'"

        for var j in 0..<myobject.orderset!.count {

          let newmess = myobject.orderset![j] as! entity

          deleteMessage(message: newmess!)


        }


Solution:


Because you had tried to delete the object in one index but the array count is decremented that's the problem for exception.So you can reverse the indexes and delete the object.


        for index in (0..< myobject.orderset!.count).reversed()             {

                let newmess = myobject.orderset![index]

          deleteMessage(message: newmess!)


            }


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift