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
is
can type or protocol, whereas argument of.iskindofclass()
must reference type (i.e. class). can test conformance@objc
protocol using.conformstoprotocol()
instead of.iskindofclass()
in same way. - the left side of
is
expression, 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
is
type must hard-coded @ compile-time. argument of.iskindofclass()
can variable or other expression value computed @ runtime.
Comments
Post a Comment