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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:26:37+00:00 2026-05-29T10:26:37+00:00

I have a Cocoa project with an object that holds information from a SQLite

  • 0

I have a Cocoa project with an object that holds information from a SQLite database.
By now the information is stored in memory by this object and is used in the user interface to read and write new information.
But now I came to a small problem… I decided to create a new controller class to handle the actions of an NSTableView and I want to access this same database object that was declared elsewhere.
Which is the best option to access this information? I wish to avoid loading the information more than once in memory and also avoid use pure C/C++ codes with global variables.

It is better to understand my point by looking at the code.
I accept other solutions as well, naturally.

My idea of code is currently like this:

FirstClass.h

#import <Foundation/Foundation.h>
#import "DatabaseModel.h"

@interface FirstClass : NSObject {

    IBOutlet NSScrollView *informationListTable;
    NSMutableArray *informationList;

}
@end

FirstClass.m

#import "FirstClass.h"

@implementation FirstClass

- (void)awakeFromNib{
    DatabaseModel *list = [[DatabaseModel alloc] init];
    informationList = [[NSMutableArray alloc] initWithArray:[list loadList]];
    [list release];
    [machinesListTable reloadData];
}

SecondClass.h

#import <Foundation/Foundation.h>

@interface SecondClass : NSObject {
    IBOutlet NSTextField *labelName;
    NSString *name;
}

- (IBAction)showName:(id)sender;

@end

SecondClass.m

#import "FirstClass.h"
#import "SecondClass.h"
@implementation SecondClass

- (IBAction)showName:(id)sender{
/*
Here name must get something like:

[[FirstClass.informationList objectAtIndex:3] name]

Here labelName must display name.
*/

}

@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-29T10:26:38+00:00Added an answer on May 29, 2026 at 10:26 am

    you can either create the object once then pass the object around, with each controller retaining it as needed. Or you can use a singleton instance. I would say the singleton instance is easier to read, but it depends on the application

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

Sidebar

Related Questions

I have an Objective-C/Cocoa project that incorporates a static library. That static library has
I have a Cocoa project that I recently imported into Xcode 4. I notice
I have a pure C++/Qt project on a Mac, but I now find that
I have a Cocoa app that uses a WebView to display an HTML interface.
I have a Cocoa app I'm writing that has an ImageView with a TextView
I have a Cocoa application that records datestamps on events. I need to know
I'm learning objective-C and Cocoa and have come across this statement: The Cocoa frameworks
I have a graphics editing cocoa app on Mac OSX that produces 32 by
I have a very simple Mac Cocoa app that just has a Web View
I have a Cocoa-AppleScript project in XCode where I'm trying to send some commands

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.