Can it help? This is my code:
class Person { public var attachValue: Any? func setAttachValue<T>(_ obj: T) { self.attachValue = obj } func getAttachValue<T>() -> T? { return attachValue as? T } }