Q:

Passing a NSString to another ViewController using classes

I know this insanely simple, but I am re-teaching myself the basics and trying to get my head around this:-)
I have one ViewController called MainVC and I have one called ClassVC
In ClassVC I have this code:
@interface ClassVC : UIViewController
{
   NSString *mainLine;
}

@property (nonatomic, retain) NSString *mainLine;
@end

and I have this in the implementation file:
@synthesize mainLine = _mainLine;

-(NSString *)_mainLine
{
    _mainLine = @"This a string from a Class";
    return _mainLine;
}

Now I was thinking that if I #import the ClassVC into MainVC I would be able to transfer that string along as well like so:
 This code is in the viewDidLoad

    _mainLabel.text = _secondClass.mainLine;

    NSLog(@"%@", _secondClass.mainLine);

But that is not working - so cannot I not pass strings in through this way???

A:

Your property is mainLine, so the overridden getter should be -(NSString *)mainLine not -(NSString *)_mainLine.
-(NSString *)mainLine
{
    _mainLine = @"This a string from a Class";
    return _mainLine;
}

This worked for me.  In the ClassVC:
@interface ClassVC : UIViewController 

@property (nonatomic, retain) NSString *mainLine;

@end

#import "ClassVC.h"

@implementation ClassVC

-(NSString *)mainLine
{
    _mainLine = @"This a string from a Class";
    return _mainLine;
}

And this in ViewController:
#import <UIKit/UIKit.h>
@class ClassVC;

@interface ViewController : UIViewController

@property (strong,nonatomic) ClassVC *secondClass;
@property (weak, nonatomic) IBOutlet UILabel *mainLabel;
@end

#import "ViewController.h"
#import "ClassVC.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    ClassVC *secondClass = [[ClassVC alloc] init];
    self.mainLabel.text = secondClass.mainLine;
     NSLog(@"%@", secondClass.mainLine);
}

