classResume: NSObject, NSCopying { var name: String var sex: String? var age: String? var timeArea: String? var company: String? //必须要有一个required的初始化方法 requiredinit(name: String) { self.name = name } funccopy(withzone: NSZone? =nil) -> Any { let obj =type(of: self).init(name: name) obj.sex = sex obj.age = age obj.timeArea = timeArea obj.company = company return obj } }
使用: let ben = Resume.init(name: "本初") var shu = ben.copy() as! Resume