{"id":5145,"date":"2014-03-30T19:12:51","date_gmt":"2014-03-30T19:12:51","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/ambiguity-with-objective-c-properties-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:12:51","modified_gmt":"2014-03-30T19:12:51","slug":"ambiguity-with-objective-c-properties-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/ambiguity-with-objective-c-properties-collection-of-common-programming-errors\/","title":{"rendered":"Ambiguity with Objective C Properties-Collection of common programming errors"},"content":{"rendered":"<p>I have gone through many questions asked here and on other forums regarding <strong><em>@property<\/em><\/strong> in Objective-C. But a question pops up every now and then..<\/p>\n<p><em><strong>Do we need i-vars to support properties?<\/strong><\/em><\/p>\n<p>Please go through the following code &#8211;<\/p>\n<p>the RootViewController.h file :-<\/p>\n<pre><code>#import \n\n@interface RootViewController : UIViewController {\n\n}\n\n@property (nonatomic, retain) NSMutableArray *arrTest;\n\n@end\n<\/code><\/pre>\n<p>The RootViewController.m is as follows &#8211;<\/p>\n<pre><code>#import \"RootViewController.h\"\n\n@implementation RootViewController\n@synthesize arrTest;\n\n#pragma mark -\n#pragma mark View lifecycle\n\n\n- (void)viewDidLoad {\n    [super viewDidLoad];\n\n    self.arrTest = [[[NSMutableArray alloc] init] autorelease];\n\n    [arrTest addObject:@\"Object1\"];\n    [arrTest addObject:@\"Object2\"];\n    [arrTest addObject:@\"Object3\"];\n    [arrTest addObject:@\"Object4\"];\n    [arrTest addObject:@\"Object5\"];\n\n    NSLog(@\"arrTest :- \\n%@\",arrTest);\n    NSLog(@\"self.arrTest :- \\n%@\",self.arrTest);\n\n\n    [self.arrTest addObject:@\"Object6\"];\n    [self.arrTest addObject:@\"Object7\"];\n    [self.arrTest addObject:@\"Object8\"];\n    [self.arrTest addObject:@\"Object9\"];\n    [self.arrTest addObject:@\"Object10\"];\n\n    NSLog(@\"arrTest :- \\n%@\",arrTest);\n    NSLog(@\"self.arrTest :- \\n%@\",self.arrTest);\n\n    \/\/ Uncomment the following line to display an Edit button in the navigation bar for this view controller.\n    \/\/ self.navigationItem.rightBarButtonItem = self.editButtonItem;\n\n}\n<\/code><\/pre>\n<p>As you can see, I have not created an instance variable to support the property.<\/p>\n<p>From this I am assuming that a variable is internally created as I can access it by just saying<\/p>\n<pre><code>[arrTest addObject:@\"Blah Blah\"];\n<\/code><\/pre>\n<p>If that is the case, then why do we need to create instance variable if we are about to declare properties?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have gone through many questions asked here and on other forums regarding @property in Objective-C. But a question pops up every now and then.. Do we need i-vars to support properties? Please go through the following code &#8211; the RootViewController.h file :- #import @interface RootViewController : UIViewController { } @property (nonatomic, retain) NSMutableArray *arrTest; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5145","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5145"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5145\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}