I hope this isn't a stupid question, I have been trawling the solutions and haven't been able to work this out..
In my main view controller I get data from a MySQL database using PHP and JSON. The user then selected relevant items from a table view by clicking on a custom button in a custom cell. I am at the point where I can add to/remove from the list based on which buttons are clicked/unclicked...
private var selectedItems = [Int: String]()
func cellButtonTapped(cell: CustomCell) {
let indexPath = self.tableView.indexPathForRowAtPoint(cell.center)!
let selectedItem = postsCollection[indexPath.row]
let item = selectedItem.product
let id = selectedItem.Id
let idItem : [Int:String] = [id:"\(item)"]
if selectedItems[id] == nil {
// now val is not nil and the Optional has been unwrapped, so use it
selectedItems[id] = "\(item)" //item
} else {
selectedItems[id] = nil
}
println("\(selectedItems)")
}
If I select items on the list it is displayed like this as I select the items. When I deselect them, the get removed from the list.
[6: Mybulen, 7: Ecotrin XL, 5: Aspen Simvastatin, 8: Lorien]
I would like to create a JSON Array and POST the array to a PHP file that I have the updates the database.. The resultant JSON Array should look something like this...
[{"Id":"6","repeatflag":"1"},{"Id":"7","repeatflag":"1"},{"Id":"5","repeatflag":"1"}]
So basically, any item I select gets added to the array with a "repeatflag" set to "1". My PHP file has a script that updates the "repeatflag" in the MySQL database. When the user is ready, they will click on a send button that will POST their selection in the the JSON Array. Hope that makes sense?
Thanks.