ios - How to replace value in array of dictionary in swift? -
i have array of dictionary, trying store in nsuserdefault contain <null>
app crash, can replace <null>
""? there way resolve issue?
this array of dictionaries:
var array = ( { clinicid = "<null>"; "patient_surveyid" = 1956; "patient_treatment_planid" = "<null>"; physicianid = "<null>"; }, { clinicid = "<null>"; "patient_surveyid" = 1956; "patient_treatment_planid" = "<null>"; physicianid = "<null>"; }, )
so have array of dictionaries
let list: [[string:any]] = []
and each dictionary of type [string:any]
.
this code replace nsnull values dictionaries ""
let list: [[string:any] = [] let updateddict = list.map { (dict) -> [string:any] in let keyswithemptstringvalue = dict.filter { $0.1 nsnull }.map { $0.0 } var dict = dict key in keyswithemptstringvalue { dict[key] = "" } return dict }
from nsmutablearray [[string:any]]
to convert nsmutablearray swift generic array please try code
let array = nsmutablearray() let list: [[string:any]] = array.flatmap { $0 as? [string:any] }
Comments
Post a Comment