Junior — Middle
Kuidas määrata andmekategooria, kuhu klass kuulub programmeerimiskeeles?
sobes.tech AI
Vastus AI-lt
In iOS (Swift/Objective-C), to determine the data category of a class, you can use:
- In Swift, the
isoperator to check for membership in a type or protocol. - The
type(of:)method to get the type of an object. - In Objective-C, the function
class_isMetaClassor the methodsisKindOfClass:andisMemberOfClass:.
Example in Swift:
class Animal {}
class Dog: Animal {}
let dog = Dog()
if dog is Animal {
print("dog belongs to the category Animal")
}
print(type(of: dog)) // Will print "Dog"
This way, you can determine which class or category an object belongs to.