When you create a @property
the compiler creates setters and getters for you automatically.
// Let's say you create a public property in your header file (.h)
@property NSObject *var;
// You synthesize your property in your implementation file (.m)
@synthesize var = _var;
// What does the compiler creates for you?
// A getter that by default has the same name as your variable
- (NSObject *)var
{
return _var;
}
// A setter that by default is called "set" + "Var" (your variable name with first letter in uppercase)
- (void)setVar:(NSObject *)var
{
_var = var;
}
Lazy instantiation is a design pattern where you chose to wait until the very last moment to instantiate your objects. So, in your case, it would be in the getter
. When someone tries to read a property that was not yet used it is time to instantiate them :D
This is what I think you want :D
// GinkgoDeliveryOrdersTableViewController.h
@interface GinkgoDeliveryOrdersTableViewController : UITableViewController
@property PFQuery *query;
@property NSArray *products;
@end
// GinkgoDeliveryOrdersTableViewController.m
@implementation GinkgoDeliveryOrdersTableViewController
@synthesize query = _query;
@synthesize products = _products;
// SETTERS
- (void)setQuery:(PFQuery *)query {
_query = query;
}
- (void)setQuery:(NSArray *)products {
_products = array;
}
// GETTERS
- (PFQuery *)query {
if (!_query)
_query = [PFQuery queryWithClassName:@"_Product"];
return _query;
}
- (NSArray *)products {
if (!_products)
_products = [_query findObjects];
return _products;
}
@synthesize
for primitive types allocates the space required for the variable.
@synthesize
for pointers to objects allocates the space required for the pointer only. You have to allocate and initialize your property.
- Do not use
_var
outside of setters and getters. Use self.var instead.
- you can change the default name for your setter and getter
@property (nonatomic, strong, setter=setVariable:, getter=getVariable) NSObject *var;
- rmaddy has the perfect answer... but I had mine saved as a draft already... I'll be faster to answer next time...