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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:20:54+00:00 2026-06-06T13:20:54+00:00

Ok. I have a class Game, which creates an instance of my class Board,

  • 0

Ok. I have a class “Game”, which creates an instance of my class “Board”, and tests it.

The “Board” class has a dictionary, which seems to somehow not being able to keep it’s values(?)
Tried to strap down the code to the minimal:

The Game class:

@interface Game : UIViewController{
    Board *board;
}
-(void)testAgain; 

@implementation Game
-(void)setup{
    board = [Board alloc]createBoard];
    [board test]; //returns right value
    [self testAgain]; //returns (null), see output below
}
-(void)testAgain{
    [board test];
}

-(void)didLoad{
    [self setup];
}

The Board Class:

@interface Board : NSObject{
@property(nonatomic, retain) NSMutableDictionary *dict;

-(Board *)createBoard;
-(void)test;

@implementation Board
@synthesize dict;

-(Board *)createBoard{

    dict = [[NSMutableDictionary alloc]init];

    [dict setObject:@"foo1" forKey:@"1"];
    [dict setObject:@"foo2" forKey:@"2"];
    [dict setObject:@"foo3" forKey:@"3"];
    [dict setObject:@"foo4" forKey:@"4"];
    [dict setObject:@"foo5" forKey:@"5"];

    return self;
}

-(void)test{
    NSLog(@"Test return: %@", [dict objectForKey:@"4"]);
}

The following output:

2012-06-23 01:05:28.614 Game[21430:207] Test return: foo4
2012-06-23 01:05:32.539 Game[21430:207] Test return: (null)

In advance, thanks for any help!

  • 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-06T13:20:55+00:00Added an answer on June 6, 2026 at 1:20 pm
    @implementation Game
    -(void)setup{
        board = [[[Board alloc] init] createBoard];
        [board test]; //returns right value
        [self testAgain]; //returns (null), see output below
    }
    

    The creation pattern you are using is outside every convention in Objective-C. You should either use [Board new], [[Board alloc] init|With…|] or [Board board|With…|].

    -(Board *)createBoard {
    
        self.dict = [[NSMutableDictionary alloc]init];
    
        [dict setObject:@"foo1" forKey:@"1"];
        [dict setObject:@"foo2" forKey:@"2"];
        [dict setObject:@"foo3" forKey:@"3"];
        [dict setObject:@"foo4" forKey:@"4"];
        [dict setObject:@"foo5" forKey:@"5"];
    }
    

    Lets see if your code works better with the missing init reinstalled where it belongs and that little missing self. .

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

Sidebar

Related Questions

My question is really short. I have a game which has a reset class
I have a C# method which creates a new instance of a class from
I am making a card game in ruby. I have the Game class, which
I have an Object Factory Class which has a method called registerCreator as defined
I have a game. It has a Level class for drawing the level, managing
I am writing a game and I have a class for the input which
I am making a game which has a global (static) class called MedGameController. In
I have a class say 'A', an object 'a' of which creates an object
I have a class with the following declaration of the fields: public class Game
I have a class called Mouse (tracking button states in a game). I want

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.