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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:48:02+00:00 2026-06-09T21:48:02+00:00

I have a simple Answer class that looks like this: @interface Answer : NSObject

  • 0

I have a simple Answer class that looks like this:

@interface Answer : NSObject {
  NSString *_text;
  NSNumber *_votes;
}

@property(nonatomic, retain) NSString *text;
@property(nonatomic, retain) NSNumber *votes;

+(id)initFromAnswerData:(NSSet *)data;
-(id)initWithText:(NSString *)answer;

@end

The implementation looks like this:

#import "Answer.h"
#import "AnswerData.h"
#import "AppDelegate.h"

@implementation Answer

@synthesize text = _text;
@synthesize votes = _votes;


-(id)initWithText:(NSString *)answer {
  if( (self=[super init])) {
    _text = answer;
    _votes = 0;
  }
  return self;
}


@end

If I create an array of Answers in a view controller using the initWithText: method I inevitably have EXC_BAD_ACCESS errors when I take an Answer in the array and try to find it’s text value.

However if I initialize a new Answer, set the text value and then add it to the array I don’t have this access issue.

So this causes problems down the line:

[arrayOfAnswers addObject:[[Answer alloc] initWithText:@"Hello"]];

But this doesn’t:

Answer *newAnswer = [[Answer alloc] initWithText:nil];
newAnswer.text = @"Hello";
[arrayOfAnswers addObject:newAnswer];

Can anyone explain why?

  • 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-09T21:48:03+00:00Added an answer on June 9, 2026 at 9:48 pm

    You’re using the attribute _text and _votes directly but not their setters.
    So, you’re not retaining the input parameter answer for the line

    _text = answer;
    

    You should either change to

    _text = [answer retain];
    

    or

    self.text = answer;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a very simple file managing database that basicly looks like this:
I am hoping that this will have a pretty quick and simple answer. I
In C# I have an intrusive tree structure that looks like this: public abstract
I have something that looks like the following document structure: public class Document {
What I want is a standard JDK class that look like this: interface ExplodingRunnable
I have a XML Structure that looks like this. <sales> <item name=Games sku=MIC28306200 iCat=28
I have a simple question and answer section on my website that allows comments.
I am looking for a simple answer for this problem... I have a UITextView
I'm sure there's a simple answer to this... or not: I have a site
I'm new to jQuery so this may be a real simple answer. 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.