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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:52:51+00:00 2026-06-02T21:52:51+00:00

To start let me tell you I am a total Objective-C beginner. This is

  • 0

To start let me tell you I am a total Objective-C beginner. This is my problem:

I have a NSMutableArray that stores objects, (Player) that has the name of the player and his/her score.

I am able to add objects to the array using addObject, but I am having trouble traversing this array. This
is how I do it:

// Get the reference to the array 
NSMutableArray *myarray = [delegate getArray];
// Create a numerator
NSEnumerator *e = [myarray objectEnumerator];
id object;
while (object = [e nextObject])
{
    [object printPlayer];
}

The method printPlayer belongs to the Player class and it just prints the name and the score.

The problem is when I have three players in the array and I am trying to print the content, it reaches this error inside the printPlayer method:

Thread 1: EXC_BAD_ACCESS(code=1, address=0x0000008)

Strangely if I use NSLog(@"%@", object); instead of [object printPlayer]; it prints a reference to the object and does not reach any error.

Anyone could point me what could be the problem when I try to use [object printPlayer]

Cheers

Update 1:
This is my printPlayer method:

-(void) printPlayer
{
    NSLog(@"\n\nName: %@\nScore: %d", playerName, playerScore);
}

Update 2:

Player.h:

@interface PROGPlayer : NSObject
@property (nonatomic, assign) NSString *playerName;
@property (nonatomic, assign) int playerScore;
-(id) init: (NSString *) n;
-(void) printPlayer;
@end

Player.m:

#import "PROGPlayer.h"
@implementation PROGPlayer

@synthesize playerName;
@synthesize playerScore;
/**
 * Player's class constructor
 * @param   n Player's name
 * @param   s Player's score
 */
-init: (NSString *) n
{
    if (!(self = [super init])) return nil;
    else 
    {
        playerName = n;
        playerScore = 0;
    }
    return self;
}

-(void) printPlayer
{
    NSLog(@"\n\nName: %@\nScore: %d", playerName, playerScore);
}
@end
  • 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-02T21:52:54+00:00Added an answer on June 2, 2026 at 9:52 pm

    Your playerName property should best be copied instead of assigned

    @property (nonatomic, copy) NSString *playerName;
    

    When trying to access the assigned value, the object most likely is gone causing the bad access.

    Also remember to release playerName in dealloc when you set the property to copy.

    Cheers

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

Sidebar

Related Questions

Let’s start with this statement: We have published couple of free applications on the
So there is a common problem that I have found in bash. Let's say
Before start let me tell my experience: I am experienced with C#.NET, web services,
Let me start by saying this is a homework assignment, I don't need any
Let me start by saying that I've never coded in Python. I need to
Let me start by saying, I like the border that chrome is using for
Let me start by telling you that I never used anything besides SVN and
Let me start out by saying that I'm not a C developer and I
Let me start by saying im not 100% the way Im handling this is
First of all let me say thank you to everyone that offered answers...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.