Questions tagged [ivar]

In object-oriented programming, an instance variable is a variable defined in a class (i.e. a member variable), for which each object of the class has a separate copy, or instance.

In object-oriented programming, an instance variable is a variable defined in a class (i.e. a member variable), for which each object of the class has a separate copy, or instance.

140 questions
3
votes
1 answer

Why doesn't this UIView get added as a subview under certain circumstances, but does under others?

I have a UIView viewForRootVc that is a declared property for a UIView subclass NewView. It's NewView's responsibility to initialize viewForRootVc, but then a subclass NewViewSubClass sets its background color. Once this is all done, the root view…
maxedison
  • 17,243
  • 14
  • 67
  • 114
3
votes
2 answers

Why do some ivars have a double underscore prefix?

When XCode creates synthesize statements in Apple's templates, you would see something like: @synthesize ivar=_ivar; So I get the single underscore, and how you name ivars differently than properties to make sure you don't accidentally access them,…
Jim
  • 2,300
  • 1
  • 19
  • 43
3
votes
1 answer

Difference between ivars and (global?) variables defined outside the brackets

What is the difference between @implementation aClass { aType *aVariable } - (void)aMethod: { } and @implementation bClass bType *bVariable - (void)bMethod: { } Is bVariable global?
Display Name
  • 4,502
  • 2
  • 47
  • 63
3
votes
1 answer

Synthesis and Protected Instance Variables in "Modern" Objective-C?

I want to create a class that serves as a base (or "abstract") class to be extended by subclasses. The best way I can explain what I'm talking about is with a few examples. Here's a possible interface for my superclass: #import…
Ben Stock
  • 1,986
  • 1
  • 22
  • 30
3
votes
2 answers

Setting default values for inherited property without using accessor

I always see people debating whether or not to use a property's setter in the -init method. My problem is how to create a default value in a subclass for an inherited property. Say we have a class called NSLawyer -- a framework class, that I can't…
Ben Stock
  • 1,986
  • 1
  • 22
  • 30
3
votes
1 answer

I want to understand when to use @property vs instance variables

I've been learning Obj-C for a while now, and I have a fundamental question. There seems to be an inordinate number of 'self's everywhere in my code. I believe it is down to a basic question about the differences between two ways to declare and use…
3
votes
2 answers

Objective-C - iVar Scoped Method Variables?

I was messing around in Objective-C earlier, and I ran into a quite common situation: I had a class, which was not a singleton, that needed a variable shared between method calls, like static, but each instance needed it's own variable. However,…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
3
votes
3 answers

Doesn't ARC eliminate the need for properties in Objective-C?

Possible Duplicate: With ARC why use @properties anymore? NB: I actually don't think we can do away with properties, but I'm trying to understand the reasoning as to why not. :) Referring back to this question, it seems like the principal reason…
Eric Brotto
  • 53,471
  • 32
  • 129
  • 174
2
votes
2 answers

Acceptable to use direct ivar access from outside the class for efficiency?

I can define a class with a property to access my ivars from outside of the class. I can also just use the myInst->ivar syntax to access in a C-struct fashion. In C++, I would go with accessors, but in objective-c there are some cases where I may…
Michael Chinen
  • 17,737
  • 5
  • 33
  • 45
2
votes
1 answer

How to change the default naming convention of generated fields in VisualStudio Mac in C#?

I am having a hard time finding this option, if it exists. By default, when VSMac generates a field it creates it as "this.fieldName" I prefer using underscore for iVars so I would like to fix it so that it creates it as "_fieldName" by default.…
Sev
  • 883
  • 1
  • 14
  • 34
2
votes
3 answers

Is there any way to add an iVar that's not in the header file (not using LLVM 2.0 or later) in Objective-C?

I recently learned that you can add ivar in a class extension with LLVM2.0. (gcc can't do this) This is somehow really private iVar because other users don't it's existence since it's not in the header file. like: //SomeClass.h @interface SomeClass…
Jimmy
  • 1,094
  • 10
  • 22
2
votes
1 answer

Why can't Swift's runtime put stored properties into the existing structure for extensions?

Swift extensions cannot contain stored properties: Because properties need storage, adding properties would change the memory structure of the class If we look closely at the runtime class struct, the Ivar list holds the property storage, and…
rishu1992
  • 1,414
  • 3
  • 14
  • 33
2
votes
2 answers

Block retaining self for CGFloat ivars?

I have a class with an ivar like this: @interface MCProgressBarView() { CGFloat minimumForegroundWidth; CGFloat availableWidth; } later in code, I have this: dispatch_async(dispatch_get_main_queue(), ^{ CGRect frame =…
Duck
  • 34,902
  • 47
  • 248
  • 470
2
votes
1 answer

Access ivar from subclass in Objective-C

I have class A which has this declaration in it's .m file: @implementation A { NSObject *trickyObject; } And class B which has this declaration in it's .h file: @interface B : A @end Is there any possibility to access the trickyObject from a…
Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
2
votes
2 answers

Controlling access to instance variables in Objective-C

From all code I've seen, almost always is used something like this for property scope definition: Class extension /*We declare the class extension*/ @interface MyClass () @property (nonatomic, retain) Type *aPrivateProperty; -…
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
1 2
3
9 10