objective c - Is there a native function that checks if a value is inside of an enum? -
i'm trying put uilabel
s inside of nsdictionary
, i'm using tags key, problem is, not of labels inside of view needed, tags of uilabel
s needed inside of enum.
so want is, check tag if exist inside of enum add dictionary tag key.
for (nsobject *obj in [self.formview subviews]) { if ([obj iskindofclass:[uilabel class]]) { uilabel *label = (uilabel *)obj; // here want add check before line labeldict[[nsstring stringwithformat:@"%d",label.tag]] = label; } }
for future readers:
if iterating on nsarray type of object code above, should use nsarray function enumerateobjectsusingblock
instead, this answer, doesn't more pretty:
[self.formview.subviews enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop) { if ([obj iskindofclass:[uilabel class]]) { uilabel *label = (uilabel *)obj; if ( label.tag >= textfieldtype_min_val && label.tag <= textfieldtype_max_val ) { labeldict[[nsstring stringwithformat:@"%d",label.tag]] = label; } } }];
objective-c enums inherited c enums , cannot reflected @ runtime. without abusing debug symbols (which overly complicated task slow , unreliable result), believe impossible come function tell if arbitrary value member of arbitrary enum.
one possible workaround create nsset contains enum values have, , check if label's tag exists within set. otherwise, if enum sequential, can check tag between enum's minimum value , maximum value.
Comments
Post a Comment