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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -