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: "Michael Ash" <email@hidden>
- Date: Tue, 19 Aug 2008 00:00:29 -0400
On Mon, Aug 18, 2008 at 11:28 PM, David <email@hidden> wrote:
> 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.
If there are things you're unsatisfied with, you'll get much better
results filing bugs on them at bugreport.apple.com rather than
complaining to the list. The people who read the list generally aren't
in a position to fix these things, and when they are they still
generally can't do anything about it unless people file bugs.
That said, I should assure you that Cocoa gets a lot more powerful and
sensible when you learn more of it. The learning curve is difficult
because it's such an integrated system. But what that means is that at
some point you reach critical mass and it will suddenly make a great
deal more sense.
Many of the things you point out are entirely legitimate (NSStream
should definitely work with NSData objects!) but ultimately, in the
grand scheme of things, they aren't all that significant.
Mike
_______________________________________________
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