Re: NSArray saveToFile: atomically does not work
Re: NSArray saveToFile: atomically does not work
- Subject: Re: NSArray saveToFile: atomically does not work
- From: Dan Saul <email@hidden>
- Date: Tue, 4 Jan 2005 17:06:00 -0600
If you must have this type of thing take a look at NSKeyedArchiver and
NSArchiver and the NSUnarchiver equivalents.
On Tue, 04 Jan 2005 12:59:31 -0500, Bruce Truax <email@hidden> wrote:
> Thank you for the explanation. Of course now that you point out how I
> misinterpreted the documentation it is all perfectly clear!
>
> Bruce
>
> On 1/4/05 12:12 PM, "Shawn Erickson" <email@hidden> eloquently
> wrote:
>
> >
> > On Jan 4, 2005, at 8:56 AM, Bruce Truax wrote:
> >
> >> I have an NSMutableArray *variableArray. This array is made of of
> >> ACVariable objects defined as follows:
> >>
> >> @interface ACVariable : NSObject {
> >
> > [snip]
> >
> >> When I try to save this array using writeToFile: atomically: as in the
> >> code
> >> snippet below it always fails.
> >>
> >> if([variableArray writeToFile:@"/Users/bruce/Desktop/variables"
> >> atomically:YES]){
> >> NSLog(@"Variable File saved successfully");
> >> }else{
> >> NSLog(@"Unable to save variable file");
> >> }
> >>
> >>
> >> According to the documentation for writeToFile: atomically: for this
> >> to work
> >> all of the receiver's contents must be property list objects, and I
> >> thought
> >> that NSNumber and NSStrings were both property list objects (at least
> >> if you
> >> go into the Propery list editor, you can add children which are
> >> numbers and
> >> strings). The documentation then parenthetically lists NSString,
> >> NSData,
> >> NSArray and NSDictionary as the allowable objects. Is it really true
> >> that
> >> you cannot use writeToFile: atomically if you have anything other than
> >> these
> >> four types of objects in your array?
> >
> > It only works if the objects in the array itself are one of the ones
> > listed in the documentation. In this case you have your own object in
> > the array. It is inconsequential that your object happens store strings
> > internally.
> >
> > In Cocoa you can only store NSNumbers, NSStrings, NSDictionary and
> > NSData object to files... just kidding ;-)
> >
> > Review the following conceptual documentation to understand the various
> > ways to go about what you want...
> >
> > <http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/
> > index.html#//apple_ref/doc/uid/10000047i>
> >
> > -Shawn
> >
>
> --
> ____________________________________________________________
> Bruce E. Truax email: email@hidden
> Optical Engineering Consultant
>
> Diffraction Limited Design LLC
> 388 Wedgewood Road voice: 860-276-0450
> Southington, CT 06489 fax: 860-620-9026
> http://www.dld-llc.com
> _____________________________________________________________
>
> _______________________________________________
> 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
>
_______________________________________________
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