last day (26 days later) » 

7:50 AM
3
A: Save tableViewItem in defaults when tableViewCell is swiped left

vadianDon't dequeue cells outside of cellForRowAt. Never do that. The cell is unused anyway. Use the dedicated API array(forKey to read the array from UserDefaults and cast the type to the expected type rather than unspecified Any(Object) func tableView(_ tableView: UITableView, editActionsForRowAt i...

 
The error message disappeared but it doesn't save the data. after marking many rows as favorite and then after printing the data as print(UserDefaults.standard.string(forKey: "favorites")) it print nil value
 
The code appends only the item at the given index path. If you want to save multiple items you have to filter the datasource array to get the favorite items and append them
 
yes i want to save multiple items in defaults can you please update your answer.
 
No I can't because I don't know how to get the cells marked as favorite. You have to change the data model to a struct to save also the favorite status of each row.
 
sir the code above do not save even the current indexpath.row. even a single word
 
7:50 AM
This is rather impossible. If itemList contains a string at the given index it must be saved. Is itemList the data source array?
 
i have updated the question. i want an array in defaults which save each item marked favorite to that array.
 
How do you know that nothing is saved?
And from the screenshot you cannot mark multiple items simultaneously.
 
print(UserDefaults.standard.string(forKey: "favorites"))
with this code
 
And what should happen if you mark an item a second time?
 
i don't want to save it simultaneously. mark will be one by one.
item one marked then mark item 5 or what even the user desires
 
7:54 AM
The code is wrong, it must be print(UserDefaults.standard.array(forKey: "favorites"))
Basically you have to extend your data source array to a struct with a name and an isFavorite property. This makes it easier to save and restore the information
 
works perfectly can we delete the indexpath.row
 
Sorry, I got to go, bye.
 
thanks for your time
 
You can remove the item at index path form the array and delete the row. But this is actually a delete action
 

last day (26 days later) »