How to replace isKindOfClass in Swift for checking object type?
Hello everyone! I just started learning Swift after Objective-C and ran into a problem. In old Objective-C projects, I often used the `isKindOfClass` method to check the type of an object at runtime. For example, I have an array with different objects, and I need to determine whether a specific object is an instance of a particular class.
Here's how I used to do it:
```objc
if ([someObject isKindOfClass:[MyCustomClass class]]) {
// do something
}
```
Now in Swift, I'm trying to write similar code, but the compiler says `isKindOfClass` is unavailable. I tried writing it like this:
```swift
if someObject.isKindOfClass(MyCustomClass.self) {
// error: Value of type 'Any' has no member 'isKindOfClass'
}
```
What am I doing wrong? How do I check in Swift whether
No answers yet.
Log in to leave an answer