Difference between Swift is and isKindOfClass()? -
is there difference between following expressions?
if someinstance someclass { } if someinstance.iskindofclass(someclass) { }
i assume .iskindofclass() instance method cocoa.
- the right side of
iscan type or protocol, whereas argument of.iskindofclass()must reference type (i.e. class). can test conformance@objcprotocol using.conformstoprotocol()instead of.iskindofclass()in same way. - the left side of
isexpression, whereas receiver of.iskindofclass()must object reference. compiler complain if compile-time class of expression not known support.iskindofclass(), can overcome casting left sideanyobject. swift classes support.iskindofclass()@ runtime. - the right side of
istype must hard-coded @ compile-time. argument of.iskindofclass()can variable or other expression value computed @ runtime.
Comments
Post a Comment