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

  • SEARCH
  • Home
  • 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 9078663
In Process

The Archive Base Latest Questions

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

Possible Duplicate: Subclass UIButton to add a property I’m trying to find a way

  • 0

Possible Duplicate:
Subclass UIButton to add a property

I’m trying to find a way to extend UIButton so that it can have a property like

@property(assign, nonatomic) id userInfos;

without subclassing it…

Is this possible?

the button.tag is not enough in my situation…

Okay as always a better answer is available here

Subclass UIButton to add a property

  • 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-16T19:40:54+00:00Added an answer on June 16, 2026 at 7:40 pm

    This is very easy using Objective-C associated objects:

    In your header:

    @interface UIButton (MyCustomProperty)
    @property (readwrite, retain, nonatomic) id myCustomProperty;
    @end
    

    In your implementation file:

    #include <objc/runtime.h>
    
    /* Associated objects need a unique memory location to use as a key. */
    static char MyCustomPropertyKey = 0;
    
    @implementation UIButton (MyCustomProperty)
    /* Use @dynamic to tell the compiler you're handling the accessors yourself. */
    @dynamic myCustomProperty;
    
    - (id)myCustomProperty {
        return objc_getAssociatedObject(self, &MyCustomPropertyKey);
    }
    
    - (void)setMyCustomProperty: (id)anObject {
        objc_setAssociatedObject(self, &MyCustomPropertyKey, anObject, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    @end
    

    That’s it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Learning to write a compiler I looked around trying to find out
Possible Duplicate: Most efficient way to cast List<SubClass> to List<BaseClass> why polymorphism doesn't treat
Possible Duplicate: Multiple Delegates in Objective C C# programmer here. I have a subclass
Possible Duplicate: How can I find all subclasses of a given class in Python?
Possible Duplicate: nth-child for every two table rows I'm trying to work my way
Possible Duplicate: Trying to get tables next to each other horizontal I have two
Possible Duplicate: Referring to a static member of a subclass Please have a look
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:

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.