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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:48:32+00:00 2026-05-28T01:48:32+00:00

I have a singleton object in iOS that when instantiated parses a CSV file

  • 0

I have a singleton object in iOS that when instantiated parses a CSV file and then holds the results. I would like to make this object universally accessible and I would like it to not be released from memory until the app quits. I am running ARC so I cannot do manual retains.

Is there a way I can do this so it will work with ARC?

Header File:

#import <Foundation/Foundation.h>
#import "CHCSV.h"
#import "RCParserObject.h"


@interface ParserStore : NSObject <CHCSVParserDelegate>
{
    // CSV Variables
    RCParserObject *item;
    NSMutableArray *data;
    NSMutableArray *parsedData;
    int fields;
    bool open;
}

@property (atomic, retain) RCParserObject *item;
@property (atomic, retain) NSMutableArray *data;
@property (atomic, retain) NSMutableArray *parsedData;
@property (atomic) int fields;
@property (atomic) bool open;

+ (ParserStore *) defaultStore;

- (void) parseCSVFile:(NSString*)file;
- (void) categorizeData;

Implementation File

#import "ParserStore.h"
#import "RCParserObject.h"
#import "RCDetailItem.h"

static ParserStore *defaultStore;

@implementation ParserStore

@synthesize item, data, parsedData, fields, open;

# pragma mark -
# pragma mark Singleton Methods

+ (ParserStore *) defaultStore
{
    if (!defaultStore) 
    {
        defaultStore = [[super allocWithZone:NULL] init];
    }
    return defaultStore;
}

+ (id) allocWithZone:(NSZone *)zone
{
    return [self defaultStore];
}

- (id) init
{
    NSLog(@"Running init on parser store");

    if (defaultStore) 
    {
        NSLog(@"Self data count is %d, right before return", self.parsedData.count);
        return defaultStore;
    }

    // NSLog(@"This better only happen once");
    self = [super init];
    [self setParsedData:[[NSMutableArray alloc] init]];
    [self parseCSVFile:@"ContentNoPathFileExt2ASCII"];
    [self categorizeData];
    // NSLog(@"Self data count is %d when first created", self.parsedData.count);

    return self;
}

    @property (atomic, retain) RCParserObject *item;
    @property (atomic, retain) NSMutableArray *data;
    @property (atomic, retain) NSMutableArray *parsedData;
    @property (atomic) int fields;
    @property (atomic) bool open;

    + (ParserStore *) defaultStore;

    - (void) parseCSVFile:(NSString*)file;
    - (void) categorizeData;

    @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-05-28T01:48:32+00:00Added an answer on May 28, 2026 at 1:48 am
    +(MySingleton *)singleton {
        static dispatch_once_t pred;
        static MySingleton *shared = nil;
        dispatch_once(&pred, ^{
            shared = [[MySingleton alloc] init];
            shared.someVar = someValue; // if you want to initialize an ivar
        });
        return shared;
    }
    

    From anywhere:

    NSLog(@"%@",[MySingleton singleton].someVar);
    

    Note that your iOS app already has a singleton that you can access anywhere:

    AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have one (global, singleton) object in my application that exposes
I have a singleton object that use another object (not singleton), to require some
Greetings, I would like to ask if creating Singleton to have only one active
I want to have singleton class that its object is not statically created. having
I have a singleton data manager object that manages the connection to a web
I have a singleton factory and would like it to return a reference to
I have a singleton object called PoolManager that loads and saves some data in
I have a singleton that uses the static readonly T Instance = new T();
I have a Singleton that is accessed in my class via a static property
I have a C# singleton class that multiple classes use. Is access through Instance

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.