{
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;
}
)
我想删除所有键重复的对象 对于前。图像类型ID = 1;对象是两次,因此想要删除 1 个对象,并且仅删除一个 ImageTypeId = 1 的对象;
最佳答案
创建一个字典来保存值:
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)
关于ios - 从 NSArray 中删除重复的键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38933644/