I\'ve heard that lazy instantiation of objects in iOS is pretty common, however I\'m not exactly sure when I should use it? Could someone give a brief explanation of when I
Not only for memory and performance, check this out, here's another example:
- (NSArray *)validElements{
if (!_validElements) {
_validElements = [[NSArray alloc] initWithObjects:
@"mystuff",@"generaldescription",@"title",@"autor",
@"version",@"date",@"context",@"operatingsystem",@"kindofdevice",
@"deviceversion",@"rule",@"daytime",@"time",@"location",@"deviceheading",
@"region",@"language",nil];
}
return _validElements;
}
You can use lazy instantiation for doing a custom init or special configuration and yes also this benefits memory and performance.