Question: I have created multiple classes, all of which need to implement the NSCopying protocol, but there are a lot of properties in my classes, is there an easier way?
Below is my current way：

```
    class TestA: NSObject, NSCopying {
    var a: CGFloat = 0
    var b: CGFloat = 0

    required override init() {

    }

    func copy(with zone: NSZone? = nil) -> Any {
        let item = type(of: self).init()
        item.a = a
        item.b = b
        return item
    }
}

class TestB: TestA {
    var c: CGFloat = 0
    var d: CGFloat = 0

    override func copy(with zone: NSZone? = nil) -> Any {
        let item = super.copy(with: zone) as! TestB
        item.c = c
        item.b = b
        return item
    }
}

```

My thought is, can we take all the properties of the class, automatically create a new object, assign values to the new object?

Answer: 
Use the initializer.

```
class TestA: NSObject, NSCopying {
    var a: CGFloat = 0
    var b: CGFloat = 0

    required override init() {}

    convenience init(a: CGFloat, b: CGFloat) {
        self.init()
        self.a = a
        self.b = b 
    }

    func copy(with zone: NSZone? = nil) -> Any {
        let item = TestA(a: a, b: b)
        return item
    }
}

```

Doing it this way doesn't really save code since you still need an initializer that takes values for all properties, but you do get a simplified `copy` method and another initializer that might be useful in other situations too.
I think I've found a solution, but I'm not sure if this will have any ill effects. Can someone tell me what's wrong with this。Thanks！

```
  @objcMembers class TestA: NSObject, NSCopying {
    var a: CGFloat = 0
    var b: CGFloat = 0
    var c: CGFloat = 0

    required override init() {

    }

    func copy(with zone: NSZone? = nil) -> Any {
        let item = type(of: self).init()
        for property in getAllPropertys() {
            let value = self.value(forKey: property)
            item.setValue(value, forKey: property)
        }
        return item
    }

    func getAllPropertys()->[String]{
        var result = [String]()
        var count:UInt32 = 0
        let proList = class_copyPropertyList(object_getClass(self),&count)
        for i in 0..<numericCast(count) {
            let property = property_getName((proList?[i])!);
            let proper = String.init(cString: property)
            result.append(proper)
          }
          return result
    }
}

```