I noticed that some generated classes declare class properties / variables via @property and do not include them in @interface, as such:
@interface AddItemViewController : UITableViewController { } @property (nonatomic, retain) UITextField *itemName;
I was just wondering if this is an acceptable way to do this, or if this is done for various reasons?
I usually do this:
@interface AddItemViewController : UITableViewController { UITextField *itemName; } @property (nonatomic, retain) UITextField *itemName;
I declare it first in @interface and then add @property for it ...
* Update *
I just wanted to update this a bit, because it is still not 100% clear to me.
I always thought that to declare @property first you need to declare it first in the @interface interface, and then I saw this:
@interface mInventoryAppDelegate : NSObject <UIApplicationDelegate> { } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext; @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel; @property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; - (void)saveContext; - (NSURL *)applicationDocumentsDirectory; @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @end
All of these @property declarations are only declared as @properties, and not inside @interface.
For example, if I said NSString *myString - I can declare that in @interface, and not like @property, and still it does not have access to it, but creators and setters will not be created. I could also declare this in both. But what if I simply declare it as @property, as such:
@interface AddItemViewController : UITableViewController { } @property (nonatomic, retain) NSString *myString;
Note that I did not add it between @interface {} - how it differs.
Sorry for repeating, but I'm just trying to change this to get an answer that makes more sense to me.