Questions tagged [ivars]
21 questions
12
votes
2 answers
Difference between @property and ivar in Xcode 4.5
Previously I have always seen example of use of properties and iVars like this...
Inside SomeClass.h
@interface SomeClass : NSObject {
NSString *_someString;
}
@property NSString *someString;
@end
Then in SomeClass.m
#import…

Fogmeister
- 76,236
- 42
- 207
- 306
7
votes
5 answers
Objective-c: why private ivars are not hidden from the outside access when using KVC
After trying to access ivars using KVC, I have noticed that there was no protection on private and protected ivars. It doesn't matter what I put a in front of the ivar (private or protected keyword) - an ivar is always a public ivar when using KVC…

Centurion
- 14,106
- 31
- 105
- 197
6
votes
3 answers
Automatic iVars with @synthesize
I understand that starting with iOS 4, there is now the ability to not declare iVars at all, and allow the compiler to automatically create them for you when you synthesize the property. However, I cannot find any documentation from Apple on this…

GendoIkari
- 11,734
- 6
- 62
- 104
4
votes
4 answers
Changing the class of an ivar (to a derived class), in a subclass
Assume I have two base classes, Container and Gizmo. Class Container has an instance variable of class Gizmo.
Now I subclass Container (call that SubContainer) and I also subclass Gizmo (SubGizmo). In some of the methods of SubContainer I need to…

Kaan Dedeoglu
- 14,765
- 5
- 40
- 41
3
votes
1 answer
When are properties in a class extension added to the class in Objective C?
I was under the impression that class extensions in Objective C were just anonymous categories. However, you may add properties to these class extensions, which is impossible in categories, so I'm a bit confused:
#import "Money.h"
@interface Money…

cfischer
- 24,452
- 37
- 131
- 214
2
votes
1 answer
Is it recommended to define ivars for readonly synthesized properties?
I have come to find that many of the times in which I want to have a synthesized readonly property, I merely implement the getter method of that property in terms of other variables with no need for an ivar, for example (Note: I am defining ivars in…

rolling_codes
- 15,174
- 22
- 76
- 112
1
vote
1 answer
What is the purpose of declaring a protocol for a variable?
I have been reading about Protocols on Objective-C but I cannot grasp this:
Consider this line
Person *person = [[Person alloc] init];
What is the purpose of declaring the variable to conform to the protocol CoordinateSupport?…

Duck
- 34,902
- 47
- 248
- 470
1
vote
3 answers
Does Using Assign reduce the amount of memory used?
When I use assign when declaring a synthesized propery, does ARC automatically still create a matching ivar to it? My property is as follows
@property (nonatomic, assign) NSString *text:
And
- (NSString *)text {
return self.label.text; // label…

rolling_codes
- 15,174
- 22
- 76
- 112
1
vote
1 answer
Accessing ivars using the . notation
Assuming I have the following class.
@interface MyObj : NSObject{
int age;
}
-(void) setAge: (int) anAge;
-(int) returnAge;
@end
@implementation MyObj
-(void) setAge:(int) anAge{
age = anAge;
}
-(int) returnAge{
return age;
}
If I…

Reck
- 81
- 6
1
vote
2 answers
Creating IBOutlets as ivars on ARC. Memory issues?
I'm aware best practices for Objective-C development says IBOutlets should always be defined as properties according to Apple.
From a practical perspective, in iOS and OS X outlets should be
defined as declared properties. Outlets should…

RGML
- 3,429
- 2
- 22
- 18
1
vote
1 answer
Cannot set iVars in XMLParser
I've made an XMLParser class in objective-c and I can't seem to set the iVars in my shared store within the parser process, I've tried numerous ways but I'm getting nowhere.
This is my code and what is being returned, Here's hoping it's a small…

Scott Browne
- 175
- 1
- 8
1
vote
1 answer
Objective-C - Static field or an ivar for a primitive type
I've recently got stuck in the middle of choosing between an ivar and static field. For instance: I need to toggle traffic lights between red and green. So I put a flag called isRed.I've so far used a static bool for this purpose and it has served…

Mikayil Abdullayev
- 12,117
- 26
- 122
- 206
1
vote
0 answers
Ivars type Nsstring in Obejctive c are nil after button event
I dont understand this yet. If I create an ivar of a class (no property). I set the ivar directly to for example @"patrik" in the - (void)viewDidLoad then the ivar value is still there when I click a button and checks for the Ivar value in the…

Patrik Persson
- 11
- 2
0
votes
3 answers
Can't get an NSString ivar to accept a value from an array
I am storing some data (some floats, some strings) to a plist and then reading them back. When I read them back, I assign them to some ivars in my view controller. They are just ivars, not properties.
The floats take their values fine and I can…

Steve
- 6,332
- 11
- 41
- 53
0
votes
1 answer
iVar LifeTime Vs Property LifeTime in Objective-C
@interface ViewController
{
NSMutableArray * GetPrices;
}
-(void)viewWillAppear:(BOOL)animated
{
GetPrices=[[NSMutableArray alloc]init];
// here I’m adding objects to the array..
}
-(void)tableView:(UITableView *)tableView…

siva krishna
- 1,149
- 2
- 15
- 23