ios - Succinctly evaluating an object with MULTIPLE class checks with isKindOfClass -
is there better way see if object has 1 of several classes than
if ([item iskindofclass:[nsarray class]] || [item iskindofclass:[nsnumber class]] || [item iskindofclass:[nspredicate class]] || [item iskindofclass:[nsmutablearray class]] || [item iskindofclass:[nsstring class]]) { return yes; };
is there more graceful way this? preferably inline way doesn't require creating categories or multiline loops/arrays.
perhaps this?
nsarray *classes = @[ [nsarray class], [nsnumber class], [nspredicate class], (etc.)]; (class cls in classes) { if ([item iskindofclass:cls]) { return yes; } }
it's not more succinct, think it's easier read , maintain.
edit : naturally, add stipulation no loops or arrays right i'm writing up. :)
you might able nspredicate , "@any.function(iskindofclass:)" keypath, don't think more graceful; people find harder read. think array , loop way go here.
Comments
Post a Comment