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

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift