Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2023 13:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Swift Array extension that removes duplicate elements, provided the elements conform to the Equatable protocol
// RemoveDuplicates.swift
// Created by João Santos on 25/05/2020.
// Copyright © 2020 João Santos. All rights reserved.
import Foundation
extension Array where Element: Equatable {
func removingDuplicates() -> [Element] {
var addedDict = [Element]()
return filter {
if addedDict.contains($0) {
return false
return true
mutating func removeDuplicates() {
self = self.removingDuplicates()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment