Core Data On Startup

Discussion in 'Mac Programming' started by Garrett, Jul 17, 2008.

  1. Garrett macrumors regular

    Joined:
    Apr 4, 2007
    #1
    I was wondering how I could achieve this, I don't need documents and documents of files. I only need one window, when the program starts it loads the xml file. Is there a way when I first start, to check if a say "clients.xml" file has been created in my Application Support folder? If there is one, read from it?

    After I can get the initial stage done, I will save it when they quit the application, or whenever they make a change. I just can't figure out how to read from a file.

    Thanks in advanced! :D
     
  2. Garrett thread starter macrumors regular

    Joined:
    Apr 4, 2007
    #2
    Anyone?

    I just want the program to read from one file is all! Or one "Core Data". :confused:
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    I'm not familiar with CoreData, but NSXMLDocument's:
    Code:
    - (id)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)mask error:(NSError **)error
    Will open an XML file and give you back an NSXMLDocument * that you can use to parse the file. error will be set if it's not there, so you can likely check that and generate a new, blank document from defaults.

    -Lee
     
  4. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #4
    Here's a full app that uses bindings and reads/saves disk-based files.

    Look in awakeFromNib in the ApplicationController.m file for the file-handing bits.
     

    Attached Files:

  5. Garrett thread starter macrumors regular

    Joined:
    Apr 4, 2007
    #5
    Thanks a lot, if this does what I think it does, then you are a godsend! :D

    Edit: I am using Core Data though :'(
     
  6. Garrett thread starter macrumors regular

    Joined:
    Apr 4, 2007
    #6
    I struggled, but I found out how, thanks for your help though!
     
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    Perhaps you could share for the benefit of others?

    -Lee
     
  8. timisted macrumors newbie

    Joined:
    Jul 18, 2008
    Location:
    UK
    #8
    Would you not simply be able to use the standard Core Data Application rather than a Document-Based App? That way, it only maintains one 'store' of information for you and you wouldn't have to worry about finding an xml file.
    Or, if you do want to be able to specify and find that file, you could change the location and type of the application's persistent store to read and write to your xml file.

    Alternatively, in a document-based application, if you've previously 'File -> Open' opened a file once, that document is stored in the app's recent documents list. You could change the default behaviour of a document application to open the most recent document rather than a new one at start up and this would maybe make it easier to find and load the file?
     
  9. Garrett thread starter macrumors regular

    Joined:
    Apr 4, 2007

Share This Page