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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:16:55+00:00 2026-05-30T23:16:55+00:00

I am writing a plugin class for a framework. My interface is defined like

  • 0

I am writing a plugin class for a framework.

My interface is defined like so:

@interface Blah : NSObject<SomeDelegate> 
{
    @private 
        NSString* _callbackID;
}

I have a private member variable as the framework will call a method in my class passing it an array containing a NSString which is required by another method in a subsequent call. I don’t want it visible outside the class.

In the first method that is called I am doing something like this:

- (void) blah:(NSArray*)blahArray 
{
    _callbackID = [blahArray objectAtIndex:0];
    MyViewController *vc = [[MyViewController alloc] init];
    vc.someDelegate = self;
    [self.viewController presentModalViewController:vc animated:YES];
    [vc release];
}

As a delegate my plugin Blah class will receive a call back from MyViewController where it will need to use this _callbackID.

  1. Am I handling the private variable correctly, and am I assigning it a value correctly?
  2. I understand I shouldn’t have to manage the NSString from the blahArray as I didn’t create it is this correct?
  3. If the call to blah was asynchronous what would stop the NSArray being cleaned up in object calling blah leaving me with nothing in _callbackID? How would I know this was the case?
  4. If the NSString _callbackID is then assigned to an existing object not under the control of the class calling blah would it have to be copied to ensure the calling class didn’t clean it up?
  • 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-30T23:16:56+00:00Added an answer on May 30, 2026 at 11:16 pm

    1. Am I handling the private variable correctly, and am I assigning it a value correctly?

    You can make it easier on yourself by always using properties. Add this to your interface (outside the braces):

    @property (nonatomic, copy) NSString *_callbackID;

    And then have the compiler automatically generate get/set methods, by adding this to your implementation:

    @sythesize _callbackID;

    Then you can just write:

    self._callbackID = [blahArray objectAtIndex:0];

    which transparently calls the automatically-generated set_callbackID method, which will copy the value (due to the copy hint in the property descriptor).

    2. I understand I shouldn’t have to manage the NSString from the blahArray as I didn’t create it is this correct?

    You are not responsible for releasing it, but if you want to keep it around, you need to either retain or copy it. Once you do that, you are responsible for releasing it (see Gilad’s answer for more).

    3. If the call to blah was asynchronous what would stop the NSArray being cleaned up in object calling blah leaving me with nothing in _callbackID? How would I know this was the case?

    By now you have probably realized that without a retain or copy, the variable could be released while you’re using it. That’s why you need to make it your own. You would know if the variable was released out from under you because your application would crash with EXC_BAD_ACCESS ;-).

    4. If the NSString _callbackID is then assigned to an existing object not under the control of the class calling blah would it have to be copied to ensure the calling class didn’t clean it up?

    Yes. And if you want to make sure a variable stays around for the duration of your function, you could write [[myVar retain] autorelease]. Then it will automatically be released at the end of the run loop (or whenever the current autorelease pool is drained).

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

Sidebar

Related Questions

I'm writing a simple plugin based program. I have an interface IPlugin which has
I'm writing a plugin (dll file), and I'm creating a WinForm as its interface/dialog.
I'm writing a C++ plugin in Mac OS X using the Carbon framework (yeah,
I am writing Qt-based app with Blender-like functionality. It consists of a 'framework' which
When writing a Maven plugin, you can configure various parameters within the mojo class,
I'm writing a plugin that adds a class method to ActionController::Base , so in
I am writing an Eclipse plugin using Xtext 2. I have provided my own
i'm writing my first plugin, but in test project, can't resolve the class of
I'm writing project in CI and I have winamp plugin that pass values to
i'm writing my first plugin for wordpress and i have some doubts regarding the

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.