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
7
votes
2 answers

Should IBOutlets be ivars or properties?

Though I'm sure they exists, I'm having difficulties finding or pinning down an official best practice for declaring outlets in a ViewController. There are 3 options so far as I can see: ivar only property only property backed with an ivar Xcode…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
6
votes
3 answers

How to find unused ivars in Xcode

Sometimes I declare an ivar but after a while I am no longer using it. I would like to remove this sort of cruft from my code, but I cannot find a warning that will show me my unused ivars. Is there a tool or built in feature of Xcode that will…
Skotch
  • 3,072
  • 2
  • 23
  • 43
5
votes
2 answers

Rails view ivars spontaneously combusting in ruby 1.9

I have a Rails 3 / ruby 1.9.2 webapp. Every so often - and it might only be 1 request in 100000 - I get an error report that I can't explain. The exact error varies, but they seem to be along the lines of having an instance variable in my view…
Jonathan del Strother
  • 2,552
  • 19
  • 32
5
votes
3 answers

Can a category access instance variables defined in the class it extends?

I know it's not a great idea to try and place properties in a category. Can I access a class' instance variables from within a category that extends it? Or is it necessary to expose an accessor on the class being extended? For example, let's say I…
Nick
  • 19,198
  • 51
  • 185
  • 312
5
votes
2 answers

Surprising Failures Putting a C Array Inside an Objective-C Struct Property

I know Objective-C doesn't allow you to use C arrays as property types. I get the compiler error I expect in that case. But I'm surprised at the behavior I'm seeing with regards to C arrays inside struct properties: No compilation errors or…
rentzsch
  • 3,548
  • 4
  • 27
  • 39
5
votes
2 answers

Why is it needed to declare ivar and property with the same name?

In most project before Xcode 4.4, I realized that developers declared simultaneous an ivar and a property with the same name. Example @interface SecondViewController : UIViewController { NSString *string; } @property (strong, retain) NSString…
Proton
  • 1,335
  • 1
  • 10
  • 16
5
votes
1 answer

Properties vs. Instance Variables

I am confused as to why some classes declare a property but do not declare an ivar and vice versa. Is it standard practice when declaring an instance variable to also declare it as a property as well? Example: @interface AppDelegate : NSObject…
GPP
  • 2,157
  • 3
  • 18
  • 26
4
votes
2 answers

Exposing/Synthesizing iVar properties in Objective c

I have a class that essentially acts as a light weight wrapper class around another class. It holds that other class as an iVar. I want to be able to expose certain properties (quite a few actually) of the iVar, but to do so I have to write out…
Aaron Hayman
  • 8,492
  • 2
  • 36
  • 63
4
votes
2 answers

Swift computed properties in Swift with instance variable?

I'm trying to create a computed property in Swift and I need an instance variable to save the state of the property. This happens specially when I'm trying to override a property in my superclass: class Jedi { var lightSaberColor =…
cfischer
  • 24,452
  • 37
  • 131
  • 214
4
votes
2 answers

Does the order of instance variable declaration matter in Objective-C?

I was searching the internet for tips to optimizing Objective-C code and came across this link. In the article I saw the note below, which I am not able to understand.
Tamil
  • 1,173
  • 1
  • 13
  • 35
4
votes
1 answer

How can I create a custom property in theos/logos?

Would it be possible to create a custom property in a hooked method using theos/logos? example: //define my custom property @interface SBAwayController : NSObject { UIView *myCustomView; } @property (nonatomic, retain) UIView…
jacob
  • 3,507
  • 2
  • 21
  • 26
4
votes
1 answer

Objective C Idioms - Properties, ivars and needsDisplay

Here's a situation I come across a lot, enough that the boilerplate code is wasteful and enough that I'm sure I can't be the only one. Is this unidiomatic, is there a better way, or do I just have to do it each time? @interface SomeUIElement :…
Ian
  • 3,619
  • 1
  • 21
  • 32
4
votes
2 answers

Under ARC, is it legal/safe to assign to an object-type ivar using runtime methods?

Based on the technique described here I'm setting ivars in object instances using the ivar_getOffset() method. Now I have the case where the ivar is a NSString*: NSString* _name; UPDATE: I was on the wrong track (can't use ivar_getOffset in this…
4
votes
2 answers

"property is backed by an ivar" ? What technically does that mean?

So ... I'm still fairly new to Objective C ... taking some iTunes U corses ... doing some exercises and all ... But when you uses to do @synthesize myProperty = _myIvarPropertyNameToUse; ... iOS 5 would create an ivar that would "back" the…
RichWalt
  • 502
  • 1
  • 4
  • 13
4
votes
3 answers

Synthesized Properties and ivar error

I've been building my program in the "Debug X86-64" mode (Xcode 3.6) and everything works flawlessly. However, I just tried switching to "Release X86-64" mode and upon compiling received the following errors for each of my properties: Synthesized…
Greg Steiner
  • 647
  • 1
  • 9
  • 20
1
2
3
9 10