[Xcode] Save NSObject to NSData

NSObject to NSData:

TestClass *objTest=[[TestClass alloc]init];
NSData *data=[NSKeyedArchiver archivedDataWithRootObject:objTest];

NSData to NSObject
NSData *dataSavedForObject;
TestClass *objTest=[NSKeyedUnarchiver unarchiveObjectWithData:dataSavedForObject];

http://my-ios-experience.blogspot.in/2013/11/save-and-retrieve-custom-object-from.html

When using Storyboard and Xib in same project…

When you extend viewcontroller that using xib

Xib will call:

– (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

But viewcontroller using storyboard wont call, so you need to define things within initwithcoder or initwithStyle

– (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Custom initialization
}
return self;
}

– (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

http://stackoverflow.com/questions/11973054/initwithnibname-method-in-storyboard