I have a dictionary of objects which are composed of UITextfield
, UITextView
and UILabel
, they all have the text
property. Now I need to get that without using an ugly approach, which is also my current code as of now:
NSString *text = @"";
if ( [obj isKindOfClass:[UITextView class]] ) {
text = [(UITextView *)obj text];
}
else if ( [obj isKindOfClass:[UITextField class]] ) {
text = [(UITextField *)obj text];
}
else if ( [obj isKindOfClass:[UILabel class]] ) {
text = [(UILabel *)obj text];
}
[array addObject:text];
Is there a way to make this shorter?