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

  • Home
  • SEARCH
  • 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 8091037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:55:45+00:00 2026-06-05T19:55:45+00:00

I have a Singleton to manage some variables I need in various places in

  • 0

I have a Singleton to manage some variables I need in various places in my app. This is the singleton, called General:

#import "General.h"

static General *sharedMyManager = nil;

@implementation General

@synthesize user;
@synthesize lon;
@synthesize lat;
@synthesize car;
@synthesize firstmess;
@synthesize firstfrom;
@synthesize numcels;

#pragma mark Singleton Methods

+ (id)sharedManager {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    if (sharedMyManager == nil) {
        sharedMyManager = [[self alloc] init];
    }
});

return sharedMyManager;
}

- (id)init {
if (self = [super init]) {
    user = [[NSString alloc] initWithString:@"vacio"];
    numcels=0;
}
return self;
}

- (void)dealloc {
// Should never be called, but just here for clarity really.
}

@end

I use it in a TableView that present in screen messages of a part of my app that is a chat.
I mean, everytime the app receives or send a message, i add 1 to the var “numcels”, and that is the value that numberOfRowsInSection method returns.

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
General *general = [General sharedManager];
return *(general.numcels); //It freezes here
}

The problem is, when i run the program, it freezes at the commented line, saying EXC_BAD_ACCESS code=2. I guess that the problema may be with the singleton, but don’t know where it is exactly.

Any help? Thank you in advance.

——-EDIT——–

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Hemos entrado en cellForRowAtIndexPath");
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if(!cell){
UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"];
}
General *general = [General sharedManager];
NSString *text=general.firstmess;//it crashes now here
NSString *remite=general.firstfrom;
[[cell textLabel]setText:remite];
[[cell detailTextLabel] setText:text];

return cell;
}

And the General.h, by request:

#import <Foundation/Foundation.h>

@interface General : NSObject {
NSString *user;
double lat;
double lon;
}

@property (nonatomic, retain) NSString *user;
@property (assign, nonatomic) double lat;
@property (assign, nonatomic) double lon;
@property (assign, nonatomic) Boolean car;
@property (assign, nonatomic) NSString *firstmess;
@property (assign, nonatomic) NSString *firstfrom;
@property (assign, nonatomic) int numcels;

+ (id)sharedManager;

@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-05T19:55:48+00:00Added an answer on June 5, 2026 at 7:55 pm

    After solving the first issue (thanks to the kind help of Ankit), it crashed in the line I have commented below the EDIT. I simply changed

    @property (nonatomc, assign) NSString *firstmess;
    

    to

    @property (retain, nonatomic) NSString *firstmess;
    

    And it doesn’t crash anymore.

    Thank you!

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

Sidebar

Related Questions

With desktop applications, to maintain global values, I usually have some singleton or static
I have a singleton class for global access to config information. This singleton class
I have a Singleton that is accessed in my class via a static property
I have a singleton object that use another object (not singleton), to require some
I have a singleton implemented like this: class Test123(object): _instance = None def __new__(cls,
I have a singleton class which is being used throughout the app. I am
In PHP, I have following Singleton Database Class: class Database { private static $instance;
I have a c++ application. I need to load some config data from file.
I've got a singleton (StoreManager) to help me manage my In-App Purchases, and it
I'm using unity to manage my services on my app server but for some

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.