ObjC get property name

Posted by Joe Even on Stack Overflow See other posts from Stack Overflow or by Joe Even
Published on 2012-06-06T10:36:32Z Indexed on 2012/06/06 10:40 UTC
Read the original article Hit count: 251

Filed under:
|
|
|
|

Yes. I've searched a lot without success.

I've looking for a way to get a property name as StringValue from inside a method.

Lets say:

My class has X Subviews from the Type UILabel.

@property (strong, nonatomic) UILabel *firstLabel;
@property (strong, nonatomic) UILabel *secondLabel;
[...]

and so on.

Inside the method foo, the views are iterated as followed:

-(void) foo 
{

for (UIView *view in self.subviews) {
 if( [view isKindOfClass:[UILabel class]] ) {
 /*
codeblock that gets the property name.
*/

 }
}

}

The Result should be something like that:

THE propertyName(NSString) OF view(UILabel) IS "firstLabel"

I've tried class_getInstanceVariable, object_getIvar and property_getName without Success.

For Example, the Code for:

[...]
property_getName((void*)&view)
[...]

RETURNS:

<UILabel: 0x6b768c0; frame = (65 375; 219 21); text = 'Something'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x6b76930>>

But i'm looking for this kind of result: "firstLabel" , "secondLabel" and so on.

Thanks for your help!

Reagrds Joé

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios