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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:05:22+00:00 2026-05-13T09:05:22+00:00

I have a problem with the init() method of a standard NSObject. I wrote

  • 0

I have a problem with the init() method of a standard NSObject. I wrote a class (EFAPersistence) which is a subclass of NSObject. EFAPersistance has a attribute called efaDatabase.

EFAPersistence.h

@interface EFAPersistence : NSObject {
  FMDatabase * efaDatabase;
}

@property (assign) FMDatabase * efaDatabase;

Everytime an instance of EFAPersistance is created I want to assign efaDatabase a value from my AppDelegate.

EFAPersistence.m

@implementation EFAPersistence

@synthesize efaDatabase;

- (id)init {
  if (self = [super init]) {
    efaDatabase = [[NSApp delegate] efaDatabase];
  }
  return self;
}

@end

This way of assigning does not work. But it works if I put the code in a normal method. So I am sure that efaDatabase is correctly instantiated in my AppDelegate. It’s just not working in my init() method. That’s why I have the feeling that NSApp is not working inside the init() method.

That’s how the important AppDelegate code looks like.

AppDelegate.h

@interface AppDelegate : NSObject <NSApplicationDelegate> {
  FMDatabase * efaDatabase;
}

AppDelegate.m

- (id)init {
  if (self = [super init]) {
    NSString * databasePath = 
      [[NSBundle mainBundle] pathForResource:@"efa" ofType:@"sqlite"];

    self.efaDatabase = [FMDatabase databaseWithPath:databasePath];

    if (![efaDatabase open]) {
      NSLog(@"Couldn't open database: %@", databasePath);
      // TODO: Create a database here
    }
    self.db = [[EFAPersistence alloc] init];
  }
  return self;
}

As you can see I am calling the init method. I also affirmed this by using NSLog(). init() is called. The attribute I am trying to assign in EFAPersistence is also created before init() is called.

To sum everything up:

How can I make this work within the init() method so I do not have to write boiler plate code in all my methods of EFAPersistence?

  • 1 1 Answer
  • 2 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-13T09:05:22+00:00Added an answer on May 13, 2026 at 9:05 am

    It looks to me that your AppDelegate is unset when you try to create the EFAPersistance object the first time. This is on below line in AppDelegate.m

    self.db = [[EFAPersistence alloc] init];
    

    I imagine the app delegate is set after the init is done (returned).

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

Sidebar

Related Questions

I have an object called Communicator. Communicator has a custom init method -(id)initWithEmail:(NSString*)theEmail andPassword:(NSString*)thePassword
Imagine I have a game with a base Entity class, with an init method
I have a windows service which fails in Init() method and throws some exception
I have the following problem: I have the class: class Word(object): def __init__(self): self.id
I have a module which supports creation of geographic objects using a company-standard interface.
I have problem with using dequeueReusableCellWithIdentifier method. Whenever I use this one, one cell
So I have a category for UINavigationController and I override the init method as
I have problem with using class instance in Python. Ive created a new class
i have the following problem. The 1st step is to implement a program, which
Please help me with the following problem: I have the following classes: class ChemicalElement

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.