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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:11:02+00:00 2026-05-28T05:11:02+00:00

I am using Core Data for the first time and was just curious if

  • 0

I am using Core Data for the first time and was just curious if what I am seeing is correct. Each time I run the application via Xcode it reports that the database, exists, is closed, and is being opened. The next time I run the app the same happens …

My question is, I am not closing the database myself and I was just curious if I have something wrong somewhere or if iOS is closing the database itself.

EDIT_001: Code Added.

- (void)viewDidLoad {
    [super viewDidLoad];
    if([self planetDatabase] == nil) {

        // CREATE MANAGED DOCUMENT
        NSLog(@"Database: Setup");
        NSArray *userDocumentPath = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
        NSURL *databaseFileURL = [[userDocumentPath lastObject] URLByAppendingPathComponent:@"DefaultPlanetDatabase"];
        [self setPlanetDatabase:[[UIManagedDocument alloc] initWithFileURL:databaseFileURL]];

        // CHECK FOR EXISTING 
        if([[NSFileManager defaultManager] fileExistsAtPath:[databaseFileURL path]]) {

            // OPEN IF CLOSED
            if([[self planetDatabase] documentState] == UIDocumentStateClosed) {
                NSLog(@"Database: Closed");
                [[self planetDatabase] openWithCompletionHandler:^(BOOL success) {
                    if(success)[self doWhatsNext];
                }];
            // USE IF NORMAL
            } else if([[self planetDatabase] documentState] == UIDocumentStateNormal) {
                [self doWhatsNext];
            }
        // CREATE AND OPEN 
        } else {
            [[self planetDatabase] saveToURL: [[self planetDatabase] fileURL] forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
                if(success)[self doWhatsNext];
            }];
        }
    }
}

The first time I run this code from within Xcode the database is created “CREATE AND OPEN” the next time I run this code “OPEN IF CLOSED” is called. I assume this is correct, but am just trying to verify that Xcode does indeed close the open database between builds.

  • 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-28T05:11:02+00:00Added an answer on May 28, 2026 at 5:11 am

    The SQLite database is not like, say MySQL. It’s not a server running somewhere. It’s just code inside your app. Hence, when you add a NSPersistenStore, the database is opened, and when your app shuts down, the database will be closed. That’s how SQLite works.

    Xcode doesn’t do anything to your database. It’s just your app touching it.

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

Sidebar

Related Questions

I'm trying to make my first application using Objective C + Core Data, but
I'm using Core Data in my first iPhone application and trying to understand NSFetchedResultsController.
I've been creating an iPhone App using Core Data. First of all, does it
I have an application using Core Data and bindings. I want to have an
I am writing an application using Core Data to control a few NSTableViews. I
I'm just starting out with using Core Data on the iPhone SDK and I'm
I'm working on my first app using Core Data and I need to assign
I'm using core data on an iPhone application. I have multiple persisntent stores that
I am using Core Data and want a Text Label to display how many
I started using Core Data for iPhone development. I started out by creating a

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.