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.
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
Post a Comment