1, OC Comparison:
-(BOOL) Iskindofclass:classobj to determine if this class or subclass of this class is an instance of
-(BOOL) ismemberofclass:classobj to determine if it is an instance of this class
2. is type check
Use the type check operator ( is
) to check for whether an instance are of a certain subclass type.
3, ( as?
or as!
) type conversion
Use the conditional form of the the type cast operator () when you were not as?
sure if the downcast would succeed.
Use the forced form of the the type cast operator () only if you were sure that the downcast would always as!
succeed.
Certainty and uncertainty of conversion.
4. Type Casting for any and anyobject
Swift provides-special types for working with nonspecific types:
Any
Can represent an instance of any type at all, including function types.
AnyObject
Can represent an instance of any class type.
To discover the specific type of a constant or variable that's known only to being of type Any
or AnyObject
, can use a or as
pattern in a switch
statement ' s cases. The
Any
the type represents values of any type, including optional types. Swift gives you a warning if your use an optional value where a value of type is Any
expected. If you really does need to use an optional value Any
as a value, you can use the as
operator to explicitly cast the OPT Ional Any
to, as shown below.
let optionalNumber: Int? = 3
things.append(optionalNumber) // Warning
things.append(optionalNumber as Any) // No warning
Swift Language Reviews 19-type conversions and checks