In Objective-C, it was simple to get the class of an instance and call class methods on it. How do you do this in Swift 4?
e.g.
MyObject * obj = [[MyObject alloc] init];
[[obj class] someClassMethod];
In Objective-C, it was simple to get the class of an instance and call class methods on it. How do you do this in Swift 4?
e.g.
MyObject * obj = [[MyObject alloc] init];
[[obj class] someClassMethod];
You can use the type(of)
method to get the class of an object, and use this to call a class method on it.
class MyObject {
static func someClassMethod() {
}
}
let obj = MyObject()
type(of: obj).someClassMethod()