Skip to content

Add the ability to tag and display tags of views. #70

@rlaferla

Description

@rlaferla

To make it easier to read debug logs, add this category and make it so that when you tap on a view, it displays the tag name along with the class name. Also, the debug output should display these tags.

e.g.

[myview setNametag:@"My main view"]

when you tap on it, DCIntrospect should display "UIView - My main view {{0,0},{320,568}}" on the top status bar. Without this, you would only see "UIView" which is not helpful when you have many views and subviews!

Category code:

@interface UIView (NameTags)

  • (NSString *)nametag;
  • (void)setNametag:(NSString *)theNametag;
  • (NSString *)objectIdentifier;
    @EnD

@implementation UIView (NameTags)

  • (NSString *)nametag {
    return (NSString *)objc_getAssociatedObject(self, @selector(nametag));
    }

// Nametag setter

  • (void)setNametag:(NSString *)theNametag {
    objc_setAssociatedObject(self, @selector(nametag), theNametag, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }

// Return 'Class description : hex memory address'

  • (NSString *)objectIdentifier {
    return [NSString stringWithFormat:@"%@:0x%0x", self.class.description, (int) self];
    }

@EnD

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions