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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:57:16+00:00 2026-05-24T13:57:16+00:00

I have this singleton: UserData.h @interface UserData : NSObject { User *user; } +

  • 0

I have this singleton:

UserData.h

@interface UserData : NSObject {
    User *user;
}

+ (UserData *)sharedUserData;

@property (nonatomic, retain) User *user;

UserData.m

@implementation UserData

@synthesize user;

SYNTHESIZE_SINGLETON_FOR_CLASS(UserData);

- (id) init
{
    self = [super init];
    if (self != nil) {
    }
    return self;
}

- (void) dealloc
{
    [user release];
    [super dealloc];
}

@end

User.h

@interface User : NSObject
{
    int user_id;
    NSString *username;
    BOOL logged_in;
}

@property (nonatomic, assign) int user_id;
@property (nonatomic, retain) NSString *username;
@property (nonatomic, assign, getter=isLogged) BOOL logged_in;

@end

User.m

@implementation User

@synthesize user_id, username, logged_in;

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }

    return self;
}

@end

in the app delegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.tabBarController;

    BOOL logged_in = FALSE; // hardcoded for testing  

    UserData *userData = [UserData sharedUserData];
    [[userData user] setLogged_in:logged_in];

    if (!logged_in) {
        [self hideTabBar:self.tabBarController];
    }

    [self.window makeKeyAndVisible];
    return YES;
}

Up to here it works like a charm. The problem is when in the LoginViewController I change the value of logged_in:

BOOL logged_in = TRUE;    

UserData *userData = [UserData sharedUserData];
[[userData user] setLogged_in:logged_in];

if (userData.user.isLogged) {
    NSLog(@"You're logged in.");
} else {
    NSLog(@"You're not logged in.");
}

The debug console says me “You’re not logged in”. Why this? What’s wrong?

  • 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-24T13:57:17+00:00Added an answer on May 24, 2026 at 1:57 pm
    - (id) init
    {
        self = [super init];
        if (self != nil) {
          self.user = [[User alloc] init];
        }
        return self;
    }
    

    You also need to allocate memory for individual element of your singleton.

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

Sidebar

Related Questions

I have a singleton class for global access to config information. This singleton class
I have a C++ singleton that runs as a separate thread. This singleton is
I have created a Registry class in .NET which is a singleton. Apparently this
Can anyone help me with this? I have this function in a singleton class.
Good morning, I would like to have an eager singleton in Unity, this singleton
I have this service which is Singleton and Single threaded and serves bunch of
I have some class it is a singleton we have this class in already
Consider this scenario we have a class A which is singleton it has a
I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need

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.