Reputation: 26223
I am still finding my feet with objective-c and was wondering if its acceptable to use @property on the two objects below.
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> {
CLLocationManager *locationManager;
IBOutlet MKMapView *googleMapView;
}
@property(nonatomic, retain) CLLocationManager *locationManager;
@property(nonatomic, retain) MKMapView *googleMapView;
@end
One of my reasons for using them is so that I can use the setters in my viewDidUnload, I seem to be using @property a lot and was just wondering if the use in this situation is acceptable?
-(void)viewDidUnload {
[self setLocationManager:nil];
[self setGoogleMapView:nil];
[super viewDidUnload];
}
much appreciated
Gary
Upvotes: 1
Views: 101
Reputation: 12770
Just a note, but you can also use the IBOutlet
keyword in property declarations. Not important in this case, but if you were synthesizing the ivars rather than declaring them explicitly, you'd need the keyword for IB to automatically see the outlet.
Upvotes: 0
Reputation: 11477
That seems totally fine with me.
The only case I can think of where it would not be acceptable would be if these properties had to be private. It is a bit trickier to make properties private, but is essential practice to hide the internals of the class from abuse!
Upvotes: 0
Reputation: 9198
Assuming you use @synthesize as well, then this is exactly what you should use it for. Don't get too hung up about 'nonatomic' and of course you could use the dot syntax if you like
self.locationManager = nil;
Upvotes: 1
Reputation: 299265
Yes. @property is extremely common. You shouldn't be surprised to use it a lot. Your viewDidUnload
is exactly correct.
Upvotes: 3