Remove Duplicate element in an NSMutableArray iOS swift

Solution:

In NSMUtablearray we can have to save the array of data or add a data to that array.But it will accept the duplicate elements.It cannot have primary keys to restrict that.So you can follow the below code to remove the duplicate elements in the final moment.


func removeDuplcate(arr:NSMutableArray)->NSMutableArray {
        let temp:NSMutableArray = NSMutableArray()
        for i in 0..<arr.count {
            if !temp.contains(arr[i]) {
                temp.add(arr[i])
            }
        }
        return temp
    }

Comments

Popular posts from this blog

How to blink a button iOS swift?

Convert NsNumber, NSDate to String in iOS Swift

Parse the value from string value iOS swift