Reordering cells in tableview & saving to iCloud

Hi,


I am very new to Swift and do it as a hobby, however I have developed a few apps and have them on the App store.


As mentioned I am self taught and and old fella at nearly 60 years of age... But I love doing this.


I have built an app that stores and retrieves data from iCloud and it works well.


But... I have researched and have come up with nothing.. when listing my records in a Tableview, I need to be able to click on a cell and move it to another position in the tableview, reorder.


But also be able to store it in the same order to iCloud via Cloudkit.


Any suggestions?


Keep it simple... please !!!!


Cheers.


Craig.

Replies

Did you implement tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) ?



Typically, you should do something like this

   override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {

        var newArray = presentArray // The present array for dataSource
        let movedItem = presentArray[fromIndexPath.row]
        newArray.remove(at: fromIndexPath.row)      // remove from present position
        newArray.insert(movedItem, at: to.row)      // insert a new position
     // Save where needed
    }

Thank you for taking the time to help me out.


How do I save the moved record so it save the new positon in icloud ?


Cheers.


Craig.

What do you save in the cloud ? The array used for dataSource or something else ?

Sorry about the slow reply..


I display data from iCloud to my Tableview, so if I was to Re-Order the cells I need to save the data in each Cell back to iCloud so it saves it in the new order.. if that makes sense.


Cheers.


Craig.