Noob- Declaring Variables

Discussion in 'iOS Programming' started by resetme, Dec 25, 2012.

  1. resetme macrumors newbie

    Joined:
    Oct 28, 2012
    #1
    Noob question, what is the difference declaring variables like this (.h file)?

    case 1:
    Code:
    @interface my App : UIViewController{
        IBOutlet UIImageView *imageView;
    }
    
    @property (weak, nonatomic) IBOutlet UIImageView *imageView;
    case 2:
    Code:
    @interface my App : UIViewController{
        IBOutlet UIImageView *imageView;
    }
    
    case 3:
    Code:
    @interface my App : UIViewController
    @property (weak, nonatomic) IBOutlet UIImageView *imageView;
    for me they all do the same.. instance variables.
     
  2. Ides macrumors member

    Joined:
    Mar 27, 2012
    #2
    Case 1: You have an instance variable called imageView and also have getter and setter methods for that variable.

    Case 2: You have only an instance variable but no getters or setters

    Case 3: you have getters and setters but no instance variable. If you do this you will need to create the instance variable when you synthesize the property, e.g @synthesize imageView = _imageView;

    Also, IBOutlets should be strong, not weak, if I'm not mistaken
     
  3. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    @synthesize isn't necessary anymore; unless I'm mistaken, an instance variable named _propertyName will be assumed.
     
  4. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #4
    I believe that you simply should use @synthesize propertyName; and it will assume _propertyName
     
  5. resetme thread starter macrumors newbie

    Joined:
    Oct 28, 2012
    #5
    Ty guys... always helpful!

    I think that weak is for default and strong for controller.
     

Share This Page