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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:56:41+00:00 2026-06-05T06:56:41+00:00

I have a question :) I often come across the case where I have

  • 0

I have a question 🙂 I often come across the case where I have some objects (books say) and a list of users. Each user has some books. There is also a special case of the currently logged in user who has more attributes than a regular user (posting rights, favorites) etc.

In all previous projects I have been creating a subclass of User called CurrentUser and am adding the current user attributes/logic in there (a regular user can not log out for example). But I always come across the problem of ensuring only one CurrentUser object exists.

How are other people doing this? And am I doing this correctly?

  • 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-05T06:56:43+00:00Added an answer on June 5, 2026 at 6:56 am

    I’m not pretty sure I understood your question, but if you want to control that there is only one instance of CurrentUser I will set up a sort of singleton class, say SessionController, that has a property of type CurrentUser.

    So, you can access that property anywhere and you know that it’s available only one instance of that class and hence only one property for your current user.

    CurrentUser* cu = [[SessionController sharedSessionController] currentUser];
    if(!cu) // allowed
    else // not allowed
    

    When you login (or something else) you populate that property. When you logout, you set it a nil. When you want to enter with another user you can check against that property. This is a simply approach that could work in most cases.

    About your question, I’m not pretty sure why you subclassed the User entity. But maybe there is some motivations for it. Make attention when you deal with subclasses. Under the hood, in fact, if you use a sqlite storage, Core Data make flattened the subclass you create. So, in your case you only have a User table which have the attributes you created in CurrentUser.

    EDIT

    Reading the title of your question, if the control has to be done with the db file, I would create an entity called LoggedUser and avoid using subclass.

    Here you can store the id for your the current user and the other properties you want.

    Then, if you want to verify if there is one user that is already logged, you could simply set up a request like the following:

    NSInteger count = [fetchRequest countForFetchRequest:&error]; // query against `LoggedUser`
    if(count >= 1) // not allowed
    else // allowed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often come accross the problem that I have a class that has a
Interview question- Often its pretty easier to debug a program once you have trouble
I have a (dump) question regarding VB/C# I often use third party classes where
I have a question about relationships between two tables. Let's say we have a
I've come into an interesting problem (as is often the case in interacting with
This is sort of a general question that has come up in several contexts,
Sometimes I come across this problem where you have a set of functions that
I have come to SO with a question after a long time, I haven't
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past 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.