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 7006325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:27:48+00:00 2026-05-27T21:27:48+00:00

I am fairly new to Objective-C and iOS programming, and I am having lots

  • 0

I am fairly new to Objective-C and iOS programming, and I am having lots of trouble passing data around. I have created a model “LevelsCompleted” where I have declared an NSString property:

@property (readwrite,copy) NSString *answersString;

I synthesized it in the .m file:

@synthesize answersString = _answersString;

Now if I change its value in one of my controllers

-(void) changeAnswersString{
    LevelsCompleted *lvls = [[LevelsCompleted alloc] init];
    [lvls setAnswersString:@"1"];
}

And then access it from a third controller:

-(void) showAnswerStringValue{
    LevelsCompleted *lvls = [[LevelsCompleted alloc]init];
    NSLog(@"%@", [lvls answersString]);
}

The console prints null instead of 1

I really can’t find a way to change data for every controller, and my english is very limited so I don’t know what to search for in documentation. Any help please?

Actual Code

// PuzzleOneViewController.m

#import "PuzzleOneViewController.h"
#import "LevelChooseViewController.h"

@interface PuzzleOneViewController(){
int thinInt;
int i;
int answer[10];
bool validSubmit, miniPresent, toDelete;
}
@end

@implementation PuzzleOneViewController

@synthesize levels;

- (IBAction)backButton:(id)sender {
if (levels ==nil) self.levels = [[LevelsCompleted alloc]init];
self.levels.answersString=@"Hello";
[self dismissModalViewControllerAnimated:NO];


}

@end

// PuzzleOneViewController.h

#import <UIKit/UIKit.h>
#import "LevelsCompleted.h"

@interface PuzzleOneViewController : UIViewController{
BOOL grosseur;
NSString *choice;
IBOutlet UIScrollView *sv;
IBOutlet UILabel *cluesLabel;
IBOutlet UILabel *hintLabelText;
   }

@property (nonatomic, retain) LevelsCompleted *levels;

- (IBAction)backButton:(id)sender;

@end

// LevelsCompleted.h THIS IS MY MODEL

#import <Foundation/Foundation.h>

@interface LevelsCompleted : NSObject
{
int hello;
BOOL success[30];
NSString *answersString;
}
@property (readwrite,copy) NSString *answersString;

-(BOOL) success:(int)number;
-(void) setSuccess:(BOOL)result atIndex:(int)number;
@end

// LevelsCompleted.m

#import "LevelsCompleted.h"

@implementation LevelsCompleted
@synthesize answersString;

-(BOOL) success:(int)number{
    return success[number];
}
-(void) setSuccess:(BOOL)result atIndex:(int)number{
    success[number] = result;
}
@end

// LevelChooseViewController.m

#import "LevelChooseViewController.h"
#import "LevelsCompleted.h"
#import "PuzzleOneViewController.h"

@implementation LevelChooseViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

-(void) viewWillAppear:(BOOL)animated{

PuzzleOneViewController *controller = [[PuzzleOneViewController alloc]init];

NSLog(@"%@",controller.levels.answersString);   // prints NULL
NSLog(@"%@", PuzzleOneViewController.levels.answersString); // Generates Error


}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"PassLevelA"]){
    [[segue destinationViewController] setChoice:_levelChoice];

}
}

- (IBAction)Level1Choose:(id)sender {

_levelChoice = [[sender currentTitle]intValue];
[self performSegueWithIdentifier:@"PassLevelA" sender:self];
}
@end

And nothing interesting in the LevelChooseViewController.h file…
I could not copy everything because my controllers have 500+ lines of code each, but I but everything relevant (i hope so…) Thanks a lot for helping

  • 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-05-27T21:27:48+00:00Added an answer on May 27, 2026 at 9:27 pm

    You’re not accessing the same LevelsCompleted object instance. [[LevelsCompleted alloc] init] creates a new LevelsCompleted instance. This is a separate object from the LevelsCompleted object you created in your changeAnswersString method. In order to access that levels completed object from the “third controller”, you need to come up with a way to share data between the two controllers. Without knowing the overall structure of your program, it’s hard to say exactly what you should do, but one easy option is to add a “levels” @property to your first controller, or maybe your application delegate, that way you can access it from other places:

    In your FirstController.h:

    @property (nonatomic, retain) LevelsCompleted *levels;
    

    In your FirstController.m:

    @synthesize levels;
    

    Then, in changeAnswersString:

    - (void)changeAnswersString
    {
        if (self.levels == nil) self.levels = [[LevelsCompleted alloc] init];
        self.levels.answersString = @"1";
    }
    

    Now, in showAnswerStringValue:

    - (void)showAnswerStringValue
    {
        NSLog(@"%@", firstController.levels.answersString);
    }
    

    As always, you should think carefully about the structure of your program. It’s impossible to convey all the things to consider in a short answer like this one, but I’d recommend reading up on standard Cocoa design patterns, particularly Model View Controller (MVC) paradigm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to objective-c and am having trouble understanding the warning message
I am fairly new to Objective C and iOS programming but am constantly trying
fairly new to Objective-C and iOS development (coming from PHP) and I have a
I'm fairly new to programming in Objective-C. While I have been able to find
So I am fairly new to objective C and iOS programming. I am learning
I am fairly new to programming and I am working with Objective C. I
I am fairly new to objective c and cocoa, however i have spent a
I'm fairly new to Objective-C and iPhone programming so I apologize if this is
Summary New to iPhone programming, I'm having trouble picking the right optimization strategy to
I am fairly new with Objective C and getting my feet wet! I have

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.