Can we get the name UILabel?

I was wondering if it is possible to get a name UILabel(not text).

Something like that:

if([label.name is equalToString:key]){
     //do something
}

I know that label.namedoes not exist, but perhaps there is something equivalent. How can i do this?

+4
source share
1 answer

You can subclass UILabel:

// Objective-C

#import <UIKit/UIKit.h>

@interface NMLabel : UILabel

@property (nonatomic, readwrite) NSString *name;

@end


// Swift
import UIKit

class NMLabel : UILabel {

    var name : String = ""

}

Or at the most basic level, you can use an existing property tag(both in Objective-C and in Swift):

label.tag = 5

// Objective-C

NSLog(@"%d", label.tag); // prints 5

// Swift

print(label.tag) // prints 5
+3
source

Source: https://habr.com/ru/post/1653445/