I have an Array of JSON Data that I want to delete nil objects and I have one object with the word Connex in a long string that I want to delete. This value is in the $0.financialInstitution field.
I've tried using filter to find the items I want to delete. My JSON data is rendering correctly.
I've tried working with the solution on this post: Check if array contains part of a string in Swift?
I get an error: Cannot convert the value of type '(String) -> Bool' to expected argument type '(RateDetail) -> Bool' when I change the array to use my JSON data.
// to remove / surpress nil values let nonNilElements = rateDetails.compactMap {$0} // this does not work //code form post noted above, updated with my search parameters and array let itemsArray = rateDetails let searchToSearch = "Connex" let filteredStrings = itemsArray.filter({(item: String) -> Bool in let stringMatch = item.lowercased().range(of: searchToSearch.lowercased()) return stringMatch != nil ? true : false }) print(filteredStrings) if (filteredStrings as NSArray).count > 0 { //Record found } else { //Record Not found }
Value in RateDetails
.RateDetail(financialInstitution: "Your Neighbourhood C.U.", variableRate: "0", sixMonths: "0", oneYear: "3.59", twoYear: "3.69", threeYear: "3.79", fourYear: "3.89", fiveYear: "3.99", date: "2019-07-01")
value to be deleted:
RatesJSON.RateDetail(financialInstitution: CANNEX on June 30, 2019 at 00:30:20 ET", variableRate: "0", sixMonths: "0", oneYear: "0", twoYear: "0", threeYear: "0", fourYear: "0", fiveYear: "0", date: "2019-07-01"),
Blank value to be deleted:
RatesJSON.RateDetail(financialInstitution: "", variableRate: "0", sixMonths: "0", oneYear: "0", twoYear: "0", threeYear: "0", fourYear: "0", fiveYear: "0", date: "2019-07-01")
- I want to delete array values that are blank
- delete the value connex that is part of a longer string stored in the financialInstitution field.