for example, I have two classes, named ClassOne
and ClassTwo
:
open class ClassOne {
open var id: String?
public init(id: String?) {
self.id = id
}
}
open class ClassTwo {
open var id: String?
open var title: String?
public init(id: String?, title: String?) {
self.id = id
self.title = title
}
}
then, create some instances:
let one = ClassOne(id: "1")
now, how to convert one
to ClassTwo
type by using one as classTwo
?
I know I can implement a function like public init(classOne: ClassOne) {}
, but I just wondering 'how to use as
on custom types?'
I noticed something called _ObjectiveCBridgeable
, is there anything similar for pure swift types?