Skip to content

Instantly share code, notes, and snippets.

@kasimte
Created January 1, 2021 01:16
Show Gist options
  • Select an option

  • Save kasimte/b29c84cd29ceb03815b3db7ee2b06855 to your computer and use it in GitHub Desktop.

Select an option

Save kasimte/b29c84cd29ceb03815b3db7ee2b06855 to your computer and use it in GitHub Desktop.

Revisions

  1. kasimte created this gist Jan 1, 2021.
    9 changes: 9 additions & 0 deletions Array+FilterEncodable.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    extension Array where Element: Encodable {
    /// - Returns: An array having removed any element of the array which is not encodable itself.
    func filterUncodable() -> [Element] {
    return self.filter { (el: Element) -> Bool in
    let encoded = try? JSONEncoder().encode(el)
    return encoded != nil ? true : false
    }
    }
    }