-1

What is the difference between:

@interface PhotoAppViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
    UIImageView * imageView;
    UIButton * choosePhotoBtn;
    UIButton * takePhotoBtn;
}

@property (nonatomic, retain) IBOutlet UIImageView * imageView;
@property (nonatomic, retain) IBOutlet UIButton * choosePhotoBtn;
@property (nonatomic, retain) IBOutlet UIButton * takePhotoBtn;

And this:

@interface PhotoAppViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@property (nonatomic, retain) IBOutlet UIImageView * imageView;
@property (nonatomic, retain) IBOutlet UIButton * choosePhotoBtn;
@property (nonatomic, retain) IBOutlet UIButton * takePhotoBtn;

What do the curly braces mean after the delegation?

Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31
cdub
  • 24,555
  • 57
  • 174
  • 303

2 Answers2

1

The "curly braces" are the scope in which instance variables, (also known as ivars) are defined. Properties are variables that can be publicly accessed (i.e. by other classes), whereas instance variables are private and can be only accessed in the scope of the class's implementation itself.

Read this and this to get an intuitive understanding about the differences between properties and ivars.

I'd strongly recommend reading Apple's documentation on Objective-C, or a good book on the same topic if the former turns out to a tad bit too technical for your taste.

Community
  • 1
  • 1
Vatsal Manot
  • 17,695
  • 9
  • 44
  • 80
  • `instance variables are private and can be only accessed in the scope of the class's implementation itself` this is actually wrong. In fact there is nothing private in ObjC – Anil Varghese Jul 10 '14 at 06:24
  • instance variables declared in interface file can be accessed from any class. its is completely exposed. – Anil Varghese Jul 10 '14 at 06:27
  • No, @Anil, ivars are by default _protected_ -- only the class itself or subclasses can access them. An ivar has to be explicitly declared `@public` in the interface to be accessible by other classes. Synthesized ivars or those declared in the implementation block are only usable by the class itself. – jscs Jul 10 '14 at 07:42
  • @JoshCaswell It was my miss understanding. Yes, ivars are protected by default i checked it. Thanks for clarifying this:) – Anil Varghese Jul 10 '14 at 09:18
1

From http://rypress.com/tutorials/objective-c/properties.html:

An object’s properties let other objects inspect or change its state. But, in a well-designed object-oriented program, it’s not possible to directly access the internal state of an object. Instead, accessor methods (getters and setters) are used as an abstraction for interacting with the object’s underlying data.

Stackoverflow Answer

Community
  • 1
  • 1
Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31