Q:

Filtering out objects by a specific object in that value

So I have a list of objects lets say sneakers for example. I get these objects by parsing JSON data. Below is the model class that I use to perform that task.
@objcMembers class SneakerInfoTemp: Object, Decodable {
//    dynamic var id = UUID().uuidString

    //list of dynamic properties that will be deserialized from the json and then passed into realm
    dynamic var brand: String?
    dynamic var category: String?
    dynamic var colorway: String?
    dynamic var currentdescription: String?
    dynamic var designer: String?
    dynamic var imagesrc: String?
    dynamic var maincolor: String?
    dynamic var name: String?
    dynamic var nickname: String?
    dynamic var price: String?
    dynamic var productlink: String?
    dynamic var productlinkhref: String?
    dynamic var releasedate: String?
    dynamic var silhouette: String?
    dynamic var technology: String?
    dynamic var webscraperorder: String?
    dynamic var webscraperstarturl: String?

    enum CodingKeys: String, CodingKey {
        case brand, category, colorway, designer, imagesrc, maincolor, name, nickname, price, productlink, productlinkhref, releasedate, silhouette, technology,webscraperorder,webscraperstarturl,currentdescription
    }

    required init(from decoder: Decoder) throws
    {
        let container = try decoder.container(keyedBy: CodingKeys.self)

        //sneaker information that will be decoded
        //made optional due to the fact that some fields don't exist with every shoe
        brand = try? container.decode(String.self, forKey: .brand)
        category = try? container.decode(String.self, forKey: .category)
        colorway = try? container.decode(String.self, forKey: .colorway)
        currentdescription = try? container.decode(String.self, forKey: .currentdescription)
        designer = try? container.decode(String.self, forKey: .designer)
        imagesrc = try? container.decode(String.self, forKey: .imagesrc)
        maincolor = try? container.decode(String.self, forKey: .maincolor)
        name = try? container.decode(String.self, forKey: .name)
        nickname = try? container.decode(String.self, forKey: .nickname)

        price = try? container.decode(String.self, forKey: .price)
        productlink = try? container.decode(String.self, forKey: .productlink)
        productlinkhref = try? container.decode(String.self, forKey: .productlinkhref)
        releasedate = try? container.decode(String.self, forKey: .releasedate)
        silhouette = try? container.decode(String.self, forKey: .silhouette)
        technology = try? container.decode(String.self, forKey: .technology)
        webscraperorder = try? container.decode(String.self, forKey: .webscraperorder)
        webscraperstarturl = try? container.decode(String.self, forKey: .webscraperstarturl)
        super.init()
    }

    required init()
    {
        super.init()
    }

    override class func primaryKey() -> String? {
        return "name"
    }

    required init(value: Any, schema: RLMSchema)
    {
        super.init(value: value, schema: schema)
    }

    required init(realm: RLMRealm, schema: RLMObjectSchema)
    {
        super.init(realm: realm, schema: schema)
    }

}

When everything is said and done I get a list of objects. The issue at hand is that some of the objects are duplicates. I tried to use a set to remove them but the set can't tell the difference between the objects. I kinda want to take this List of objects and add them to the set based off of some property, lets say the name
I want to do something like this 
   let objectSet = Set((sneakersTemp.sneakers?.brands?.adidas.map { $0.name })!)
        print(objectSet.count)

It returns all unique names but is there anyway for me to get all the unique objects as well.

A:

To remove duplicates by using a Set, the type should conform to Hashable.
To simplify things, let's suppose the SneakerInfoTemp class is defined like so:
class SneakerInfoTemp {
    let name: String
    let price: Double

    init(name: String, price: Double) {
        self.name = name
        self.price = price
    }
}

Let's conform to the necessary prorocols:
extension SneakerInfoTemp: Equatable {
    static func == (lhs: SneakerInfoTemp, rhs: SneakerInfoTemp) -> Bool {
        return lhs.name == rhs.name
    }
}

extension SneakerInfoTemp: Hashable {
    func hash(into hasher: inout Hasher) {
        hasher.combine(name)
    }
}

So given an array of sneakers :
var array = [SneakerInfoTemp(name: "a", price: 1),
             SneakerInfoTemp(name: "b", price: 2),
             SneakerInfoTemp(name: "a", price: 3),
]

You can create a set of unique elements by using a Set:
let set = Set(array)

