List of class properties in Objective-C

前端 未结 6 1942
南方客
南方客 2020-11-29 17:32

Is there a way to get an array of class properties of certain kind? For example if i have interface like this

@interface MyClass : NSObject
    @property (st         


        
6条回答
  •  春和景丽
    2020-11-29 18:10

    use attributeKeys method of NSObject.

        for (NSString *key in [self attributeKeys]) {
    
            id attribute = [self valueForKey:key];
    
            if([attribute isKindOfClass:[UILabel  class]])
            {
             //put attribute to your array
            }
        }
    

提交回复
热议问题