• 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: How to write a string to a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to write a string to a file


  • Subject: Re: How to write a string to a file
  • From: Alex Kac <email@hidden>
  • Date: Mon, 18 Aug 2008 23:26:51 -0500

On Aug 18, 2008, at 10:59 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.



Funny, I find that the more I learn about Cocoa, the more consistent it is.


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.

They usually are - but the terminology is the hard part. OS X uses terminology that - while very consistent in itself - is different than UNIX or Windows many times.


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.

Paths are strings - so that makes sense. Dealing with paths is a very common thing and its not technically part of NSString - its a category of NSString that Apple wrote. I find it very helpful.


Basic methods should exist somewhere for writing primitive types to a file.

They do. Its in NSCoder. Or use NSData to take any primitive type and turn it into a byte stream. Then use NSFileHandle to write it.


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?

writeToFile is available in LOTS of classes. I just did a API search and it came up with a couple screenfuls.


Similarly, NSFileHandle and NSOutputStream could have methods to write
primitive types, or at least NSString.

They handle bytes. Use NSData to convert it to bytes. Why is this hard or wrong?


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.

Its a terminology issue. Mac OS has had that same terminology for many many many years. Look - I've been doing Windows development since 2000 in C++ as well as a little in .NET. I also did some original OS 7/8 development way back when in Pascal - years ago. I spent a year lurking on this group starting early 2007 to get an idea of the main questions and issues Cocoa devs had as well as learning Obj-C and learning why things are done a certain way. That helped me a lot as it helped gel a ton of concepts and bits of terminology that when I finally did dive into Cocoa full time 4-5 months ago it felt natural. Since then I've come across many many times when I couldn't find the answer to something simple - only to find that my terminology was wrong and bam - it was there. It does help that I have an experienced Apple dev on my team too that I can go to when I can't seem to find what I'm looking for.


But this very same question hit me last week that you had. It took me all of 30 minutes to find the answer in the Apple docs because of its consistency. I attribute that to taking that year to really learn the way OS X "thinks".

I consider myself past the hump, but still on a journey of learning and so hopefully my two cents will give hope and maybe some help :)


Alex Kac - President and Founder Web Information Solutions, Inc.

"I am not young enough to know everything."
--Oscar Wilde




_______________________________________________

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


  • Prev by Date: Re: How to write a string to a file
  • Next by Date: Re: How to write a string to a file
  • Previous by thread: Re: How to write a string to a file
  • Next by thread: Shared NSTextView
  • Index(es):
    • Date
    • Thread