Re: How to write a string to a file
Re: How to write a string to a file
- Subject: Re: How to write a string to a file
- From: David <email@hidden>
- Date: Mon, 18 Aug 2008 23:28:47 -0400
Thanks for the quick responses. Why isn't this already in NSString?I found
an old reference saying to use [filehandle writeData:[nsstring
dataUsingEncoding:...]]
This seems obtuse. I have been using Cocoa for 6 months and it is not
seeming any more consistent nor powerful than when I started.
I find Cocoa to be inconsistent with random pockets of powerful features
with many areas of spotty coverage of basic methods that I'd expect to be
present.
Some issues:
NSString includes lots of methods to work with paths, URLs, etc. This breaks
encapsulation. It does not seem to be good design for NSString to have this
unique function dealing with paths. That should be in another class.
Basic methods should exist somewhere for writing primitive types to a file.
NSString writeToFile seems like an odd method. Why just this one means to
write in this class? Why such an emphasis on atomic, which seems like such a
complex uncommon algorithm? Why is there no option to append to a file?
Similarly, NSFileHandle and NSOutputStream could have methods to write
primitive types, or at least NSString.
NSOutputStream provides the following method,
- (NSInteger)write:(const uint8_t *)*buffer* maxLength:(NSUInteger)*length*
Why doesn't it use NSData? What's the point of having the NSData construct
if it isn't even used?
I could go on, but I should stop. The method name makeKeyAndOrderFront
amazes me on NSWindow. It took me way too long to find that. It is my
current winner for least discoverable name.
On Mon, Aug 18, 2008 at 11:00 PM, David <email@hidden> wrote:
> I know it sounds like a basic question, but I've looked and it doesn't seem
> as obvious to me as it should.
> I want to write out data to a file to describe my tree structure.
>
> I'd like to have a method which appends a string to the end of a text file.
>
> I don't really want to store everything in memory and write out one big
> string because it might get quite large.
>
> How are you supposed to do this in Cocoa? Why isn't it more obvious?
>
> I've looked in NSString, NSData, NSFileHandle, NSOutputStream, but I don't
> see a simple way to append a string to a file. Can it really be this hard?
>
> NSString doesn't have a method to append to a file, nor a stream, nor
> NSData.
> And the other classes don't have a method to accept a string.
>
> Thanks
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden