1

Please look to the following code.

FirstViewController.h:

@interface FirstViewController : UIViewController {
    NSString* inputData;
}

@property (nonatomic, copy/retain) NSString* inputData;

FirstViewController.m:

@synthesize inputData;

SecondViewController.m:

- (IBAction)buttonSaveDown {
    [firstViewController setInputData:@"Text"];
    firstViewController.inputData = @"Text";
    firstViewController.inputData = [[NSString stringWithString:@"Text"] retain];
}

Add breakpoints after every line with inputData. Check firstViewController.inputData - it's '(null)'! Why?

Printing description of inputData:
(null)

Also I try 'Edit value' in the debugger. After setting value the result is '(null)' too.

There's no any warnings on the build. Please help anybody. Thanks a lot!

To moderators: Sorry, but someone deleted the same previous question when I asked to delete all comments on it.

Dmitry
  • 14,306
  • 23
  • 105
  • 189
  • 1
    Is FirstViewController initialized? Also on your 3rd attempt of setting inputData you do not need the retain call if your @property directive is set to copy or retain, this will actually cause a memory leak. – Chris Wagner Aug 22 '11 at 19:25
  • 3
    Are you sure that firstViewController is valid in the buttonSaveDown method? If it's nil, then none of that will work. – Flyingdiver Aug 22 '11 at 19:25

2 Answers2

3

Your firstViewController variable is not set to anything. You need to set it to a valid instance of FirstViewController before you can do anything useful with it.

Chuck
  • 234,037
  • 30
  • 302
  • 389
1

Just use

@property (nonatomic, retain) NSString* inputData;

Then these each should work:

[firstViewController setInputData:@"Text"];
firstViewController.inputData = @"Text";
firstViewController.inputData = [NSString stringWithString:@"Text"];
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • Don't help. inputData: '(null)'. Sorry, but it's incorrect answer. – Dmitry Aug 22 '11 at 19:26
  • 1
    regardless, 'copy/retain' is an invalid syntax, as far as I know. Pick one of the two. See http://stackoverflow.com/questions/387959/nsstring-property-copy-or-retain for suggestions on which. – Doug Kress Aug 22 '11 at 19:28