Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rlaferla opened this issue Feb 4, 2014 · 0 comments
Open

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

rlaferla opened this issue Feb 4, 2014 · 0 comments

Comments

@rlaferla
Copy link

rlaferla commented Feb 4, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant