Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Results 1 to 5 of 5
  1. #1
    martinatkinson's Avatar
    martinatkinson is offline Registered User
    Join Date
    Jun 2001
    Location
    Granger, IN, USA
    Posts
    517
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Someone help please?

    Hello!

    I really need someones help! I have a Cocoa Document-based app. It has two NSTextViews and two NSTextFields. I have found out how to write the content of one NSTextView to disk when the user saves the document. I need to know how to save the contents of all four fields to disk and be able to put them in the correct fields when the document is viewed.

    Can anyone help or refer me to a person/website that can help!

    All help is greatly appreciated, have a great day!

    Albert
    iWorship — Worship software for your Mac
    Free public beta available!
    http://www.renovatiosw.com/

  2. #2
    blb
    blb is offline `'
    Join Date
    Apr 2001
    Location
    CO, USA
    Posts
    651
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you don't want to do anything fancy with the file but store those text objects, how about putting them into an NSArray and using NSArchive/NSUnarchive to write/read them?

    Writing:
    Code:
    NSArray *someArray = [ NSArray arrayWithObjects:text,fields,here,nil ];
    if( [ NSArchiver archiveRootObject:someArray
                     toFile:@"/tmp/archfile" ] == YES )
       // do something when successful here
    else
       // do something when fails here
    Reading back:
    Code:
    NSArray *readArray = [ NSUnarchiver unarchiveObjectWithFile:@"/tmp/archfile" ];
    
    // then just [ readArray objectAtIndex:0 ]
    // and :1 :2 etc...

  3. #3
    martinatkinson's Avatar
    martinatkinson is offline Registered User
    Join Date
    Jun 2001
    Location
    Granger, IN, USA
    Posts
    517
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Hello!

    Thanks for your help!

    I am totally lost though, where do I put this code? MyDocument.m? main.m?

    One more question, does this code allow the user to specify where to save the file? From what it looks like, your code writes it out to a specific file. I will not be doing any formatting or coloring of the text but I need to be able to alow the user to save the file where they want and create a new, blank file if they want to.

    Have a great day!

    Albert
    Last edited by martinatkinson; October 21st, 2001 at 04:30 PM.
    iWorship — Worship software for your Mac
    Free public beta available!
    http://www.renovatiosw.com/

  4. #4
    blb
    blb is offline `'
    Join Date
    Apr 2001
    Location
    CO, USA
    Posts
    651
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The toFile: argument on NSArchive and the only argument for the NSUnarchive specify the file to use; I simply used a static string since I'm lazy when it comes to short code examples...just plop an NSString variable there instead, which would be the filename the user specifies wherever you have them specify that.

  5. #5
    martinatkinson's Avatar
    martinatkinson is offline Registered User
    Join Date
    Jun 2001
    Location
    Granger, IN, USA
    Posts
    517
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Sorry to keep bugging you...

    Hello!

    Thanks for your help! This doesn't seem to be working with my project though. Sorry about that, I appreciate your willingness to help!

    I guess what I am looking for is the code I need to put in the following blocks (in MyDocument.m):

    - (void)windowControllerDidLoadNib:(NSWindowController *) aController
    {
    }

    - (NSData *)dataRepresentationOfType:(NSString *)aType
    {
    }

    - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
    {
    }

    I have made outlets for the text fields in MyDocument.h and connected them to the fields in Interface Builder. Let me know if you need the names of the outlets.

    Thanks and have a great day!

    Albert
    iWorship — Worship software for your Mac
    Free public beta available!
    http://www.renovatiosw.com/

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •