English 中文(简体)
在建筑之间关闭核心数据数据库?
原标题:Core Data database closing between builds?

我第一次使用核心数据,如果我看到情况正确,那是很奇怪的。 每当我通过X代码管理申请时,我都报告说,该数据库已经存在,已经关闭,并且正在开放。 我的下一次情况也是如此......。

我的问题是,我不是关闭数据库,如果我有点错,或者如果是关闭数据库,那么我是很奇怪的。

<>strong>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];
            }];
        }
    }
}

我第一次从X条码中操作这一代码,而数据库是“CREATE and OPEN”创建的,这是我下届提出“OPENIF CLOSED”的。 我认为这是正确的,但只是试图核实Xcode确实关闭了建筑之间的开放数据库。

最佳回答

正如MySQL一样,Kumite数据库并不喜欢。 它并不是一个服务器,在其他地方运行。 这在你看来是公正的。 因此,当你增加一座NSPersistenStore时,该数据库已经开放,如果你估计关闭,数据库将关闭。 这说明“贱民”是如何运作的。

Xcode对你的数据库没有任何影响。 这只是你对它的看法。

问题回答

暂无回答




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签