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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:26:36+00:00 2026-05-23T06:26:36+00:00

I have a class called SqliteImageAccess that is going to have various methods that

  • 0

I have a class called SqliteImageAccess that is going to have various methods that provide support for some sqlite functionality. I have a local class variable of type sqlite3 and a class method called opendb. This class method should do one thing and one thing only. Open the database.

The only sticky point here is that my sqlite3 object is going to be an instance variable and Objective-C, for whatever weird reason, doesn’t let you access instance variables inside of class methods. Obviously, in other languages, when you instantiate a class, the constructor of that class might call a private method to initialize some local class variables(local private variable perhaps). I want to do the same thing with my sqlite3 object through the equivalent of an Objective-C class constructor method. Perhaps someone can help because I am stuck on this one.

Obviously in another class I can instantiate the SqliteImageAccess class and then call the opendb method. That works fine. I don’t want to have to do that. When i instantiate the class the goal is so that the class will handle the opening of the database automatically.

Lastly, with the other methods that are going to be available to do other sqlite work(inserts, etc), i am going to need full access to the db object. thanks in advance for any help.

//SqliteImageAccess.h

@interface SqliteImageAccess : NSObject {



}

+(void)opendb; //class method

@end

//SqliteImageAccess.m

#import "SqliteImageAccess.h"


@implementation SqliteImageAccess

static sqlite3 *db;

+(void)initialize{
    [self opendb];
}

+(void)opendb{
int open = sqlite3_open("/Users/csmith/RPG/cws.sqlite3", &db);
if(open == SQLITE_OK){
    NSLog(@"Database was opened successfully");
}
else {
    NSLog(@"open result = %d", open);
}

}

@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-23T06:26:37+00:00Added an answer on May 23, 2026 at 6:26 am

    In the interface you declare opendb as a class methode (+) but your are using – in the implementation. Normaly you should get a warning, that your class implementation isn’t complete. Change the – to + to implement opendb as a class method and call it via

    [self opendb];
    

    Further, + (void)initilaize is only called once during program life cycle, in think you would like to go with

    -(id) init;
    

    Seeing one more thing, your sqlite3 property is declared as an instance variable, so you can’t call it from a class method! You have to move the sqlite3 *db from the .h to the .m file as

    static sqlite3 *db;
    

    after @implementation.

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

Sidebar

Related Questions

I have class called Chicken and in Chicken I have some methods, so in
I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
Let's say I have a class called Store that has many Employees. My RESTful
I have Class CustomDate and that is referred in other class called Test. public
I have a class called fraction, and I'm declaring some operators as friends. I
I have a class called Foo that looks like this: class Foo < ActiveRecord::Base
I have a container class (called Atom) that I want to store objects of
I have a class called Foo that has a function that looks like the
I have a class called Partner, that I need to Submit all the info
I have a class called Foo that defines a list of objects of type

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.