I have a JSON array fetching from url and convert using SwiftyJSON. Now i want to update some value of JSON Array for some functionality.
My JSON is like
[
{
"id" : 48845152,
"studentPhotoTakenCount" : 0,
"updatedAt" : null,
"isAttendedToday: false
},
{ "id" : 48845153,
"studentPhotoTakenCount" : 0,
"updatedAt" : null,
"isAttendedToday: false
},
]
After some action i want to update my JSON Array by filtering id. Like if i have id = 48845152 then only update
{
"id" : 48845152,
"studentPhotoTakenCount" : 0,
"updatedAt" : null,
"isAttendedToday: false
}
and finally merge with my JSON Array. So the final result should be
[
{
"id" : 48845152,
"studentPhotoTakenCount" : 0,
"updatedAt" : null,
"isAttendedToday: false
},
{ "id" : 48845153,
"studentPhotoTakenCount" : 0,
"updatedAt" : null,
"isAttendedToday: false
},
]
My code is like that.
self.studentList.forEach {
if let id = $0["id"].int {
if id == _studentId {
$0["isAttendedToday"] = true
self.filteredStudentList.append($0)
}
else {
self.filteredStudentList.append($0)
}
}
}
Here self.studentList is my JSON. But i get the error saying that
Cannot assign through subscript: '$0' is immutable
Please someOne help me to find out what getting wrong here.