Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am new in swift and I am also trying to use Alamofire to call data from API. I am quite puzzled on how I will use the
PUT Request
to update data. I've read some solutions here in SO but I don't know how I will apply on my app. I am creating an Event App, the scenario should be, when the participant clicked the
Check In
Button, it will update the
registered_flag
to
true
meaning the participant will marked as
Registered
and the button will be changed to
Check Out
. I really don't know if my API Service is correct or not. Hope you could help me. Thank you so much.
JSON of the Event Participant Where in the registered_flag should be updated once checkInOutButton
"event_name": "Q & A",
"event_participants": [
"participant_id": "70984656-92bc-4c36-9314-2c741f068523",
"employee_number": null,
"last_name": "Surname",
"first_name": "FirstName",
"middle_name": null,
"display_name": "Surname, FirstName ",
"department_name": "Medical Informatics",
"position_name": "Application Developer",
"registered_flag": true,
"registered_datetime": "2018-09-13T08:54:40.150",
"registration_type": 1,
"delete_flag": false,
"manual_reg_flag": false,
"out_flag": false,
"out_datetime": null,
"classification": 6,
"others": "Guest"
JSON to update for check in
"registered_flag": true,
"registration_type": 1
updateType
enum UpdateParticipantType: String {
case checkIn = "Check In"
case checkOut = "Check Out"
APIService for UpdateParticipant
func updateParticipant(updateType: UpdateParticipantType,
participantID: String,
successBlock: @escaping ([Attendee]) -> Void,
failureBlock: @escaping (Error) -> Void)
let updateParticipantURL = URL(string: "\(REGISTER_PARTICIPANT_URL)/\(updateType)/\(participantID)")
Alamofire.request(updateParticipantURL!, method: .put).responseJSON { (response) in
print(response)
if let error = response.error
failureBlock(error)
print(error)
return
if let jsonArray = response.result.value as? [[String : Any]] {
for anItem in jsonArray {
if let eventparticipants = anItem["event_participants"] as? [[String : Any]] {
var extractedAttendees = [Attendee]()
for participants in eventparticipants{
let success = Attendee.init(JSON: participants)
extractedAttendees.append(success!)
successBlock(extractedAttendees)
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.