0

Add new array (addObjectFromArray) to NSMutableOrederedSet, how to check if the NSMutableOrederset already has an existing copy of item/items and no duplication happens?

Code :

 Alamofire.request(.GET, jsonUrl).responseJSON(){
                (_, _, JSON, _) in

    if JSON != nil {

                let imageInfos = (JSON!.valueForKey("image") as [NSDictionary]).map {
                    ImageInfo(id: $0["id"] as String, url: $0["url"] as String)
                }
                self.tableData.addObjectsFromArray(imageInfos)


Same for both viewDidLoad() and handlePullToRefresh()
  • jsonUrl is different for the two methods
moz ado
  • 490
  • 4
  • 17
  • NSMutable(Ordered)Set is a collection of *distinct* items. You cannot add duplicate objects. The addition of an object which is already contained in the set is simply ignored. – Martin R Apr 22 '15 at 11:32
  • here is my situation, in viewDidLoad -> JsonImage -> array containing id an url of image. when pull to refresh -> new set of jsonImage -> array containing only ids and url of new image and adding it to the existing NSMutableOrderedSet. Every time i pull to refresh the new images gets duplicated – moz ado Apr 22 '15 at 11:39
  • 1
    Could you please provide the code. What objects do store in the NSMutableOrederedSet ? the object must implement isEqual method correctly – Kostiantyn Koval Apr 22 '15 at 12:18
  • 2
    Check your implementation of `isEqual` and `hash`. – A-Live Apr 22 '15 at 12:40
  • Thank you very much for the feed back, i did not implement isEqual and hash method and that was the problem. – moz ado Apr 22 '15 at 13:16

0 Answers0