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 3457998
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:55:44+00:00 2026-05-18T09:55:44+00:00

I have a category on an existing class that adds a property and a

  • 0

I have a category on an existing class that adds a property and a few methods to the class.

@interface AClass (ACategory) {
    NSString *aProperty;
}

@property (nonatomic, retain) NSString *aProperty;

@end

In the implementation file, I want to release this property when the object is deallocated. However, if I declare dealloc in this class, it will override the dealloc from the original class from what I understand. What then is the proper way to release this aProperty when the object is deallocated?

@implementation AClass (ACategory)

@synthesize aProperty;

- (void)dealloc {
    [aProperty release];
    // this will skip the original dealloc method from what I understand
    [super dealloc];
}

@end
  • 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-05-18T09:55:44+00:00Added an answer on May 18, 2026 at 9:55 am

    Well, this is a little problematic, since your code is wrong.

    1. You can’t declare instance variables in a category; using the latest Objective-C ABI, you can declare new instance variables within a class extension (@interface AClass () {//...), but that is different from a category (@interface AClass (ACategory)).
    2. Even if you could, the syntax for instance variable declaration is that they be enclosed in curly braces after the @interface line.

    You can declare a property in a category, but you’ll have to define its storage without using a new instance variable (hence, @dynamic instead of @synthesize).


    As to your actual question, you can’t call the original implementation of an overridden method unless you use method-swizzling (facilitated by runtime functions like method_exchangeImplementations). I recommend against doing this anyway; it’s really frightening and dangerous.


    Update: Explanation of Instance Variables in Class Extensions

    A class extension is like a category, but it is anonymous and must be placed within the .m file associated with the original class. It looks like:

    @interface SomeClass () {
        // any extra instance variables you wish to add
    }
    @property (nonatomic, copy) NSString *aProperty;
    @end
    

    Its implementation must be in the main @implementation block for your class. Thus:

    @implementation SomeClass
    // synthesize any properties from the original interface
    @synthesize aProperty;
    // this will synthesize an instance variable and accessors for aProperty,
    // which was declared in the class extension.
    - (void)dealloc {
        [aProperty release];
        // perform other memory management
        [super dealloc];
    }
    @end
    

    So, a class extension is useful for keeping private instance variables and methods out of the public interface, but will not help you add instance variables to a class over which you haven’t control. There is no issue with overriding -dealloc, because you just implement it like you normally would, whilst including any necessary memory management for the instance variables you introduced within the class extension.

    Please note that this stuff works only with the latest 64-bit Objective-C ABI.

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

Sidebar

Related Questions

I have an existing page of /programs/kids.php that I want to load a category
we know that using category we can add functions to existing class. But i
I have category model that has a tree structure. In my database I have
I have a category system that is related many-to-many with posts. How can I
I have a category tree and i'd like to get all products that are
I have 3 category pages for a photography website that are loaded dynamically from
Lets suppose that I have a Category table with a column that holds the
I have a blog-like application with stories and categories: class Category(models.Model): ... class Story(models.Model):
I have an existing site that I'd like to convert to use routing, and
Just want to check: If you have a class that uses a method added

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.