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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:02:11+00:00 2026-05-30T18:02:11+00:00

Hey guys I am trying to build a database that maps NSStrings to int.

  • 0

Hey guys I am trying to build a database that maps NSStrings to int. I have on class called Movie.h where each object has a name and a number assigned:

//Movie.h
@interface Movie : NSObject
{
    int m_num;
    NSString *m_name;
}
@property int m_num;
@property(nonatomic, retain) NSString *m_name;
@end

//Movie.m
@implementation Movie
@synthesize m_num, m_name;
@end

I then have another class called Map where I am implementing functions to play with my “Movies”. One of the function is called insert, and it inserts an object of class movie into an array where all movies should be stored. The code compiles but my “m_array” does not seem to keep a record of what I add to it. Here is the code:

//Map.h
#import "Movie.h"
@interface Map : NSObject
{
@private
    int m_count;
    NSMutableArray *m_array;
}
@property int m_count;
@property(nonatomic, retain) NSMutableArray *m_array;
-(bool) contain: (NSString *) name;
-(bool) insert: (NSString *) name: (int) chap;
@end

//Map.m
@implementation Map
@synthesize m_count, m_array;

//Constructor
-(id) init{
    if (self = [super init]){
        m_count = 0;
    }
    return self;
}
-(bool) contain: (NSString *) name{
    bool b = false;
    for (int i = 0; i < m_count; i++) {
        Movie *m = [[Movie alloc]init];
        m = [m_array objectAtIndex:i];
        NSLog(@"%@ came out in %i", m.m_name, m.m_num);
        if (m.m_name == name) {
            b = true;
        }
    } 
    return b;
}
-(bool) insert:(NSString *) name: (int) chap{
    Movie *m1 = [[Movie alloc]init];
    m1.m_name = name;
    m1.m_num = chap;
    [m_array addObject:m1];
    NSLog(@"Here is the object %@",[m_array objectAtIndex:m_count]);
    m_count++;
    return true;
}
@end

-(bool) upgrade:(NSString *)name :(int)chap{
    if(![self contain:name])
        return false;
    for (int i = 0; i < m_count; i++){
        Movie *m = [[Movie alloc]init];
        m = [m_array objectAtIndex:i];
        if(m.m_name == name)
            m.m_num = chap;
    }
    return true;

}

Here’s my main:

//main.m
#import "Map.h"

int main (int argc, const char * argv[])
{
    @autoreleasepool 
    {
        Map *m = [[Map alloc]init];
        [m insert:@"James Bond" :2001];
        if (![m contain:@"James Bond"]) {
            NSLog(@"It does not work");
        }
    }
    return 0;
}

Here’s the console output:

2012-02-27 14:20:04.923 myMap[3926:707] Here is the object (null)
2012-02-27 14:20:05.036 myMap[3926:707] (null) came out in 0
2012-02-27 14:20:05.037 myMap[3926:707] It does not work
  • 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-30T18:02:13+00:00Added an answer on May 30, 2026 at 6:02 pm

    It looks like you forgot to create the array:

    - (id)init
    {
      self = [super init]
      if (nil != self) {
        m_count = 0;
        m_array = [NSMutableArray new]; << here
      }
      return self;
    }
    

    Without creating it, it’s just nil.

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

Sidebar

Related Questions

Hey guys i'm trying to build a little app that pulls in the users
Hey guys, I am trying to build an app that will use a compass
Hey guys, I've been trying to build something simple in Flash 8, and I
Hey guys, I am just trying to pull all the records from my database
Hey guys i have been trying to download it from the below link http://www.enterprisedb.com/products-services-training/pgdownload
Hey guys, I'm currently trying to implement a function using C that takes in
Hey Guys, I'm trying to add to a dictionary, and recieveing the Object reference
Hey guys. I'm working in WinForms and trying to create a ComboBox control that
hey guys what I am trying to do is have two edit boxes for
Hey guys, I have a problem (again). This time I am trying to use

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.