Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No ivars -> What am I missing?

I never use ivars. I only use properties -- sometimes assign properties with primitive types, and sometimes on a "private" class extension. I've seen the advantages of not using ivars in switching to ARC -- I have some borrowed code with lots of ivars that I still can't "ARC", since I don't know what needs to be retained. So I know some advantages of not using ivars, but what are the advantages of using ivars instead of properties?

Note: I depend exclusively on the ivars that are automagically added in (by the compiler?) for the property declaration.

Don't mark to close: I've looked at some of the other questions, like this and this and none hit the spot. The titles look good, but like so many questions on SO, the questions are a mess of strange doubts and other stuff.

like image 803
Dan Rosenstark Avatar asked Sep 14 '11 15:09

Dan Rosenstark


People also ask

Did Ivar ever show remorse for his actions?

Ivar ha has always been generally psychotic, so the moments in which he appeared remorseful didn't make much sense. He laughed like the Joker when learned of Siggy's death and didn't even feel terrible when he heard about the settlers that had been killed in Wessex.

Is Ivar the Boneless good or bad?

Ivar Ragnarsson, named Ivar the Boneless by his father due to his disease, is the evil sociopathic youngest son of Ragnar Lothbrok and Aslaug and the second King of Kattegat after his father and main antagonist of Season 5 and 6. He swears revenge on Lagertha for killing his mother and against Kings Aelle and Ecbert for Ragnar's death.

What happens to Ivar's mother in the book Ivar?

Ivar returns to Kattegat, to discover that his mother has been killed by Lagertha. Ivar challenges Lagertha to single combat, but is refused, and promises that he will kill Lagertha one day. A man in a black cloak with one eye brings news of Ragnar's death to Ivar.

Does Høgh Andersen have anything to say about Ivar?

Not if Høgh Andersen had anything to say about it. Instead, the show tacked hard in the opposite direction, away from the singular and toward the mundane. Rather than something outlandish, Ivar finds himself face-to-face with an anonymous enemy soldier on the battlefield.


1 Answers

Declared properties cannot be treated in the same manner as an @protected ivar. You can declare the property in a class extension to keep it private from any other class, or declare it in the header interface to make it publicly accessible, however there is no way to make it accessible only to subclasses. This would require the ivar declaration.

EDIT

Just another brief thought. I have recently been writing a lot of framework classes, and I think there might be something to be said for using iVars as documentation.

For example, let's say you are calling some code in a tight loop and you want to ensure that it is performant. Inside that tight loop you want to access a property of a class, but need to know whether each time you call it the return value is calculated on-the-fly or stored in an iVar. Seeing the iVar in the header is a quick way to ensure that you'll get that variable back without much overhead.

like image 129
Stuart Avatar answered Oct 18 '22 20:10

Stuart