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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:13:54+00:00 2026-06-11T07:13:54+00:00

I have an issue, described below and solution. But I think our solution is

  • 0

I have an issue, described below and solution. But I think our solution is not really “right way” to solve this issue.

1: I have thread safe singleton for Data

//DataSingleton.h
@interface DataSingleton : NSObject
@property (nonatomic, readonly, retain) NSString *userLogin;
-(void)setPrettyLogin:(NSString*)prettyLogin;
@end

and

//DataSingleton.m
#import "DataSingleton.h"

@synthesize userLogin   = _userLogin;

+(id)sharedSingleton{

    static dispatch_once_t DataSPred;
    static DataSingleton *shared = nil;
    dispatch_once(&DataSPred, ^{ shared = [[self alloc] init]; });
    return shared;
}

-(void)setPrettyLogin:(NSString*)prettyLogin{
    _userLogin = prettyLogin;
}

@end

2: Also I have same singleton for Network and i use feature

[NSURLConnection sendAsynchronousRequest:request 
     queue:[NSOperationQueue mainQueue] 
     completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
         { <block> }];
// I know about mainQueue - only for UI. Here it is, for clarity.

3: The issue

When i try get [[DataSingleton sharedSingleton] userLogin] within NSURLConnection block (in one of NetworkSingleton methods) – i get same time and in _userLogin i found some garbage =(

4:Bad solution

I spend about an hour and don’t find correct answer for my question. And create this:

//DataSingleton.h
@interface DataSingleton : NSObject{
    NSString* _userLogin;
}

-(NSString*)userLogin;
-(void)setPrettyLogin:(NSString*)prettyLogin;
@end

and

//DataSingleton.m
#import "DataSingleton.h"

+(id)sharedSingleton{

    static dispatch_once_t DataSPred;
    static DataSingleton *shared = nil;
    dispatch_once(&DataSPred, ^{ shared = [[self alloc] init]; });
    return shared;
}

-(NSString*)userLogin{
    return _userLogin;
}

-(void)setPrettyLogin:(NSString*)prettyLogin{

    _userLogin = [prettyLogin retain];
    //I can,t release it and 
    //static code analysis is not happy with what is happening
}

@end

Are any one have the idea?

Best regards
Sergey

  • 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-11T07:13:56+00:00Added an answer on June 11, 2026 at 7:13 am

    You have to retain the value in the setter. Actually the problem has nothing to do with threading.

    Your function is almost correct.

    -(void)setPrettyLogin:(NSString*)prettyLogin {
        _userLogin = [prettyLogin retain];
    }
    

    But it should be

    -(void)setPrettyLogin:(NSString*)prettyLogin {
        if (_userLogin != prettyLogin) {
             NSString *tmp = _userLogin;
             _userLogin = [prettyLogin retain];
             [tmp release];
        } 
    }
    
    -(void)dealloc {
        [_userLogin release];
        [super dealloc];
    }
    

    Now if you wan’t to release the value call

    [[DataSingleton sharedSingleton] setPrettyLogin:nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck on an issue described below Suppose we have a string like
I have found a solution but it is not the best so I am
I'm seeing basically the same issue described here I have a table that starts
I have an issue which I could not find answer for across the web.
I am having the same issue described at this address http://www.cocoabuilder.com/archive/cocoa/288659-iphone-nsmanagedobjectcontext-save-doesn-crash-but-breaks-on-objc-exception-throw.html I am debugging
IE6 is always surprising me but this one is REALLY odd. I'm creating a
I have a question in JavaScript context. I'm a little confused by this issue.
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
We are new to ROR, We have issue in creating Login/Logout process in ROR

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.