13

Hey i just start ios programming today and i am facing this erro.

plz help me to remove this error

plz suggest me some nice ios developer tutorial

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *txtUsername;
@property (weak, nonatomic) IBOutlet UITextField *txtPassword;
- (IBAction)loginClicked:(id)sender;
- (IBAction)backgroundClick:(id)sender;


@end
TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
Nik
  • 638
  • 2
  • 11
  • 24

3 Answers3

20

If you're not using ARC, you cannot use weak. For IBOutlet references in non-ARC code, replace your references to weak with retain, instead. (It's a little confusing, but generally you use assign rather than weak in non-ARC code, but for IBOutlet references, you use retain.)

Better yet, as nneonneo suggests, you should use ARC.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • I'm not sure about the use of retain for IBOutlet on non-arc code. If you use IBOutlet for objects created on a XIB you don't have the ownership of them so you should use assign. – Diogo T Mar 11 '14 at 23:41
  • @diogot I'm not unsympathetic to your position, but Apple historically advised that `retain` for outlets in pre-ARC code. It may be to avoid dangling pointers in iOS 5.x and earlier when views were released. The `viewDidUnload` documentation seems to reinforce the message that this is where one was supposed to release one's outlets. – Rob Mar 12 '14 at 02:39
  • I was pretty sure about the `assign`, but I searched around and even without found an official doc I found some evidences that `retain` should be used instead. – Diogo T Mar 12 '14 at 16:58
9

If you're just starting off, you should just enable ARC. It will save you a lot of headaches, and it will resolve that issue.

Community
  • 1
  • 1
nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • 3
    Others will argue that people just starting out should disable ARC so they can learn and understand memory management better. Using ARC is much easier but you don't learn what is going on. The same argument can be made for using IB versus doing the UI in code. IB makes some things easier, but when it doesn't work, you have no idea what to do. – rmaddy Mar 01 '13 at 04:35
  • 3
    @rmaddy: I agree with you, people and freshers in IT ( newbies) opts for simpler solutin rather than complex. And this is a vast discussion topic. And no-one can win in this topic. – Anoop Vaidya Mar 01 '13 at 04:43
  • @rmaddy: I might agree, except that ARC is a huge win in so many cases where it would be too easy for a beginner to mess up the `retain`s and `release`s. ARC doesn't free you from having to deal with memory management, but it deals with enough of the nasty (automatic) stuff that programmers can focus on the problems at hand. – nneonneo Mar 01 '13 at 04:54
  • @nneonneo I agree: As the [Advanced Memory Management](https://developer.apple.com/library/mac/documentation/cocoa/conceptual/memorymgmt/articles/MemoryMgmt.html) guide says: "In [ARC], the system uses the same reference counting system as MRR, but it inserts the appropriate memory management method calls for you at compile-time. You are strongly encouraged to use ARC for new projects. If you use ARC, there is typically no need to understand the underlying implementation described in this document, although it may in some situations be helpful." I guess it agrees with both you and rmaddy. – Rob Dec 06 '13 at 17:50
0

You can read this web page http://designthencode.com/scratch/ to start learning iOS programming.

It is a very good introduction to many of the elements involved in writing an app for iPhone.

Refer this stackoverflow answer below for your issue with property declaration.

Properties and Instance Variables in Objective-C

Community
  • 1
  • 1
Only You
  • 2,051
  • 1
  • 21
  • 34