Question

So this is weird.

I have a property:

@property (weak, nonatomic) Something *something; // .h
@synthesize something=_something                  // .m

For some reason, setting that property isn't keeping _something set.

I even wrote a setter:

- (void)setSomething:(Something *)something {
    _something = something;
}

The passed something is a valid instance of the object. However, after stepping through the line _something = something, _something is nil and something is still a valid object.

This is making me crazy, because everything looks right to me. I've written this same kind of thing a thousand times. The only thing that's new is that this is in Xcode 4.3.

Any help would be appreciated. Thanks!

ETA: So, perhaps this is a hint? viewDidLoad is being called a whole whackload of times, in batches of 4. I'm using storyboards, so the view is automatically set properly. Maybe the view controller isn't properly getting loaded or initialized or something? I've got the class set and everything looks like it should be working, but it isn't.

Was it helpful?

Solution

OK, I figured it out. I'm not sure where this method came from, but this was in the SomethingViewControler code:

- (void)loadView {
    // If you create your views manually, you MUST override this method and use it to create your views.
    // If you use Interface Builder to create your views, then you must NOT override this method.
}

Because I'm using storyboards, the very presence of this method caused all manner of problems. I'm pretty embarrassed, because I probably copied it and pasted it from somewhere without thinking about it.

Anyway, I hope this helps someone. It only killed most of my day.

OTHER TIPS

Maybe the thing you're assigning to that property is't pointed to from anywhere else. So after the assignment the only pointer to that object is your property and it's week so the object is thrown out of heap

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top