Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSUserDefault , Alloc init vs standard Userdefault

i am confused that what is difference between

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];

and

NSUserDefaults *userDefault = [[NSUserDefaults alloc] init];

can any one can help me......

thnx in advance

like image 242
Prashant Tukadiya Avatar asked Jan 06 '23 06:01

Prashant Tukadiya


1 Answers

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];

the above line gives you the singleton object by using the class method standardUserDefaults the object received by this method is allocated single memory throughout the application.

NSUserDefaults *userDefault = [[NSUserDefaults alloc] init];

this will gives you the new object, each object is allocated a different memory and deallocated when object scope is finished.

If you want to store and use the value throughout the application then its better to use singleton object and that will be deallocated when you delete your application

like image 150
Suhas Arvind Patil Avatar answered Jan 14 '23 12:01

Suhas Arvind Patil