Lae
Lae

Reputation: 942

xCode: "Property access result unused" when trying to make key window

(I'm using xCode 7.0.1 on El Capitan)

So I have a main window and a button there and I also have another window which is not visible at first. The idea is to click the button and make the main window close and at the same time make the other window key and order it to front. Here's my code so far:

- (IBAction)makeNewWindow:(id)sender {
    _newWindow.makeKeyWindow;
    _window.close;
}

However, when I enter this code, xCode gives me a warning saying "property access result unused - getters should not be used for side effects".

I tried looking for the reason the error pops up but none of the questions were related to mine.

NOTE: I am not linking the button to the two windows because if I do, it only keeps the task last given and does not complete the previous one.

Any thoughts on what I should do?

Upvotes: 0

Views: 56

Answers (2)

Lae
Lae

Reputation: 942

After fiddling around for a few minutes I ended up with this piece of code that works. (Credit to @zaph for helping)

- (IBAction)makeNewWindow:(id)sender {
    [self.window close];
    [self.newWindow orderFront:(_newWindow)];
}

Upvotes: 0

zaph
zaph

Reputation: 112857

Dot notation (_newWindow.becomeKeyWindow) is meant to be used to access properties, not to call methods, particularly methods that have side effects.

Instead use method calling syntax:

[self.newWindow becomeKeyWindow];

It really is best, a best practice, to use self. (self.newWindow) when using properties, not the variable directly with a leading underscore (_newWindow).

Upvotes: 1

Related Questions