Search code examples
objective-ccocoa-touchautomatic-ref-countingselfweak-references

Can we use self.prefix name for weak properties in ARC


I am working on a ARC based project.

I have declared a property for tableView as follows

@property (weak, nonatomic) IBOutlet UITableView *logTable.

In the ViewDidLoad I do the following

 - (void)viewDidLoad
{
    [super viewDidLoad];

    [self.logTable.layer setCornerRadius:8.0f];//First Method

   /////OR

    [logTable.layer setCornerRadius:8.0f]; //Second Method

}

My question is, which is the best method i.e First or Second in my case?

I am aware that when we don't use self , we are directly accessing the ivar.But will it make

any difference in case of Weak properties.

EDIT:

Suppose if I have a strong Property as follows

@property(strong,nonatomic)NSArray *dataArray;

As far as I know , this will cause the memory leak

self.dataArray =[[NSArray alloc]init];

So which approach to be followed in this case ?

Any help is greatly appreciated.


Solution

  • I suggest using self. for properties unless there's a necessary reason not to, such as inside a custom access method. It results in code that requires less analysis when you come back to read it at some future time and it has less chance of bugs if you decide to change the property attributes some day.