Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:15:01+00:00 2026-06-10T21:15:01+00:00

I know this insanely simple, but I am re-teaching myself the basics and trying

  • 0

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???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:15:03+00:00Added an answer on June 10, 2026 at 9:15 pm

    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);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is simple but my brain is fried from trying to solve
I know there is an insanely simple solution to this, but for the life
Know this might be rather basic, but I been trying to figure out how
I know this is an old question, but I have spend any hours on
I know this is probably something simple but I can't seem to find anything
I know this is an easy concept, but I just can't seem to get
I know this might be a simple question but Im new to Java, my
I know this should be an easy one, but I'm failing to make it
I know this is a long shot, but I have a huge text file
new to this site, but my head is absolutely killing me after trying for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.