0

I have my default initialiser:

- (id)init
{
    if ((self = [super init]))
    {   
    }

    return self;
}

I have only included this method in my class to track whether it was performing it's job, and from what I can tell, it is.

Self is getting set,and in the console I can see that self has a memory address which is not 0x0000000. For example, here is the console from a run I just tried:

self    IssueManager *  0x08383ad0

However, when the method returns self to this method:

- (id)initWithNibName:(NSString *)nibNameOrNil
               bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self)
            self.issueManager                           = [[IssueManager alloc] init];

        return self;
    }

self.issueManager remains an empty pointer:

_issueManager   IssueManager *  0x00000000

I have no idea why this is the case, but would appreciate any help.

Infinity James
  • 4,667
  • 5
  • 23
  • 36

2 Answers2

2

Instead of using:

self.issueManager

try:

issueManager = [[IssueManager alloc] init];

Remember, using the dot notation is simply using the accessor/setter methods provided by @property and @synthesize. In your init method, you should not use accessor/setter methods.

Matias
  • 176
  • 4
  • I removed the self.issueManager and replaced it with _issueManager. The IDE then warned me that assigning this to a weak pointer would mean that by the end of the function it would have been set to nil already. Therefore, I did what you said, but also made it a strong pointer. This has fixed the problem. In 4 minutes I will accept your answer, thank you. – Infinity James Oct 18 '12 at 14:27
0

I would not use an accessor in -init* (read this: Why shouldn't I use Objective C 2.0 accessors in init/dealloc?)

There is an Apple statement on this as well.

Try to do instead:

_issueManager = [[IssueManager alloc] init];
Community
  • 1
  • 1
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193