Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:24:52+00:00 2026-06-16T01:24:52+00:00

Does anyone know if there is a way to set a property like a

  • 0

Does anyone know if there is a way to set a property like a string in the User Defined Runtime Atributes sections of Interface Builder without creating a subclass of said component? For example, I want to store a metadata value for each component in my interface that I use later. I just don’t want to have to create a subclass or each component to add a metadata property.

This is one approach I came up with. Opinions?

#import <UIKit/UIKit.h>
#import <objc/runtime.h>


@interface UIControl(MetaData)

@property (nonatomic, retain) id entityProperty;

@end

@implementation  UIControl(MetaData)

static char const * const EntityPropertyKey = "EntityProperty";

@dynamic entityProperty;

- (id)entityProperty {
    return objc_getAssociatedObject(self, EntityPropertyKey);
}

- (void)setEntityProperty:(id)newEntityProperty {
    objc_setAssociatedObject(self, EntityPropertyKey, newEntityProperty,     OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}


@end

…

if (textField.entityProperty) 
     [managedObject setValue: textField.text forKey:textField.entityProperty];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:24:53+00:00Added an answer on June 16, 2026 at 1:24 am

    You could keep an NSDictionary somewhere, perhaps in a singleton object that has methods for issuing unique ids for objects and storing metadata by the id keys in the dictionary. The UI objects have a tag property that you can use, if your ids are just incremented integers. Then the dictionary keys would just be NSNumbers for those unique integers.

    Like this:

    #import <Foundation/Foundation.h>
    
    @interface ACLMetadataManager : NSArray
    
    +(ACLMetadataManager*) sharedMetadataManager;
    -(NSUInteger) getUniqueId;
    -(void) setObject: (id) object forId:(NSUInteger) theId;
    -(id) objectForId:(NSUInteger) theId;
    
    @end
    

    And:

    #import "ACLMetadataManager.h"
    @implementation ACLMetadataManager { // Private variables
        NSMutableDictionary *_metadata;
        NSUInteger _ids;
    }
    
    - (id)init {
        self = [super init];
        if (self) {
            _metadata = [[NSMutableDictionary alloc] init];
        }
        return self;
    }
    
    +(ACLMetadataManager*) sharedMetadataManager { // Singleton getter
        static ACLMetadataManager *instance;
        if (instance != nil) {
            return instance;
        }
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
        static dispatch_once_t oneTimeThread;
        dispatch_once(&oneTimeThread, ^(void) {
            instance = [[ACLMetadataManager alloc] init];
        });
    #else
        @synchronized(self) {
            instance = [[ACLMetadataManager alloc] init];
        }
    #endif
        return instance;
    }
    
    -(NSUInteger) getUniqueId { // Increment unique id when getter is called.
        return ++_ids; // Start from 1 because tag is 0 by default.
    }
    
    -(void) setObject: (id) object forId:(NSUInteger) theId {
        [_metadata setObject:object forKey:[NSNumber numberWithInteger:theId]];
    }
    
    -(id) objectForId:(NSUInteger) theId {
        return [_metadata objectForKey:[NSNumber numberWithInteger:theId]];
    }
    
    // Override some methods to ensure singleton stays instantiated.
    - (id) retain {
        return self;
    }
    - (oneway void) release {
        // Does nothing here.
    }
    - (id) autorelease {
        return self;
    }
    - (NSUInteger) retainCount {
        return INT32_MAX;
    }
    @end
    

    Usage:

    ACLMetadataManager *metadataManager = [ACLMetadataManager sharedMetadataManager];
    myControl.tag = [metadataManager getUniqueId];
    [metadataManager setObject:myMetadata forId:myControl.tag];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know is there a way to implement Windows Live ID authentication into
Does anyone know there have any other way that (by not using json_encode and
Does anyone know if there is a way to generate different code in the
Does anyone know if there's a way to check the number of messages in
Does anyone know if there's a way to access past app installs via the
Does anyone know do there have any way that I can encrypt the array
Does anyone know if there's a short-hand or convient way of disabling all of
Does anyone know if there is a way to disable scroll bars in the
Does anyone know if there any way that I can programmatically create a bean
does anyone know if there is a simple way to bind a textblock to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.