2016-08-13 100 views
0
{ 
     ImageName = "http://192.168.1.8:9701/190214/190214_image2_08_13_2016_11_55_44.jpg"; 
     ImagePath = "<null>"; 
     ImageTypeId = 2; 
    }, 
     { 
     ImageName = "http://192.168.1.8:9701/190214/190214_image3_08_13_2016_11_55_45.jpg"; 
     ImagePath = "<null>"; 
     ImageTypeId = 3; 
    }, 
     { 
     ImageName = "http://192.168.1.8:9701/190214/190214_image4_08_13_2016_11_55_48.jpg"; 
     ImagePath = "<null>"; 
     ImageTypeId = 4; 
    }, 
     { 
     ImageName = "http://192.168.1.8:9701/190214/190214_image5_08_13_2016_11_55_51.jpg"; 
     ImagePath = "<null>"; 
     ImageTypeId = 5; 
    }, 
     { 
     ImageName = "http://192.168.1.8:9701/190214/190214_image6_08_13_2016_11_55_53.jpg"; 
     ImagePath = "<null>"; 
     ImageTypeId = 6; 
    }, 
     { 
     ImageName = "http://192.168.1.8:9701/190214/190214_image0_08_13_2016_06_15_21.jpg"; 
     ImagePath = "<null>"; 
     ImageTypeId = 0; 
    }, 
     { 
     ImageName = "http://192.168.1.8:9701/190214/190214_image1_08_13_2016_07_19_57.jpg"; 
     ImagePath = "<null>"; 
     ImageTypeId = 1; 
    }, 
     { 
     ImageName = "http://192.168.1.8:9701/190214/190214_image1_08_13_2016_07_19_57.jpg"; 
     ImagePath = "<null>"; 
     ImageTypeId = 1; 
    } 
) 

我想刪除所有對象的鍵是重複的 For Ex。 ImageTypeId = 1;對象是兩次,所以想要刪除1個對象,並且只有一個ImageTypeId = 1的對象;從NSArray中刪除重複的鍵值

+0

我需要獨特的ImageTypeId = 1值 – ZetrixWeb

+0

您是否需要保存順序? –

+0

不,不需要重複的ImageTypeId,它應該是唯一的 – ZetrixWeb

回答

0

創建字典保持值:

var dict = [NSObject: AnyObject]() 

每個項目添加到使用typeid作爲密鑰詞典:

for item in arr { 
    guard let typeid = item["ImageTypeId"] as? NSObject else { continue } 
    dict[typeid] = item 
} 

與字典中的值創建一個數組:

let newarray = Array(dict.values)