Remove the duplicate values in an array iOS swift

 Problem:

I had an array that contains duplicate values.How do i remove the duplicate values?

Solution:

extension Array where Element: Equatable {

    func removingDuplicates() -> Array {

        return reduce(into: []) { result, element in

            if !result.contains(element) {

                result.append(element)

            }

        }

    }

}

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift