• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie question on saving data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question on saving data


  • Subject: Re: Newbie question on saving data
  • From: "John C. Randolph" <email@hidden>
  • Date: Tue, 9 Nov 2004 18:59:45 -0800


On Nov 8, 2004, at 6:07 PM, Steve Gran wrote:




>You can generate XML data using NSPropertyListSerialization: > >NSPropertyListSerialization >http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ >ObjC_classic/Classes/NSPropertyListSerialztion.html > >Use NSPropertyListXMLFormat_v1_0 as the format.


Wow, now I'm really confused. I guess that's what I get for being a newbie trying to learn programming.


:)

So do I use this method within the dataRepresentationOfType:(NSString *)aType method?

No, the -dataRepresentationOfType: and -loadDataRepresentationOfType: are for the simple case, where you don't want to bother with file I/O, but know how to get your info in and out of a plain old byte buffer.


If you want to go one level lower, and have to deal with the file in question directly, you would not implement -dataRepresentationOfType:, but rather -writeToFile:ofType: and -readFromFile:ofType:.

Assuming that "myArray" contains a set of strings, dates, etc, a typical implementation of -writeToFile:ofType: might be:

- (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)docType
{
id myPlist = [myArray propertyList]; // gets a text description of myArray
return [myPlist writeToFile:fileName atomically:YES]; // this will return YES if successful.
}



-jcr




John C. Randolph <email@hidden> (408) 974-8819 Sr. Cocoa Software Engineer, Apple Worldwide Developer Relations http://developer.apple.com/cocoa/index.html


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: Newbie question on saving data (From: Steve Gran <email@hidden>)

  • Prev by Date: Re: Problems with performSelector:withObject:afterDelay:
  • Next by Date: Changing height of rows in NSBrowser
  • Previous by thread: Re: Newbie question on saving data
  • Next by thread: Re: Newbie question on saving data
  • Index(es):
    • Date
    • Thread