• 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
A handy console output category .
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A handy console output category .


  • Subject: A handy console output category .
  • From: "John C. Randolph" <email@hidden>
  • Date: Tue, 15 Nov 2011 00:24:43 -0800

Hi All,

Recently, I was writing a command-line tool and I didn't feel like dropping down to printf() for console output,  so I wrote this category.

Drop this in your project…

> @interface NSString (console)
>
> - (void) writeToFileHandle:(NSFileHandle *) handle;
> - (void) writeToStdOut;
> - (void) writeToStdErr;
>
> @end
>
> @implementation NSString (console)
>
> - (void) writeToFileHandle:(NSFileHandle *) handle { [handle writeData:[self dataUsingEncoding:NSUTF8StringEncoding]]; }
> - (void) writeToStdOut { [self writeToFileHandle:[NSFileHandle fileHandleWithStandardOutput]]; }
> - (void) writeToStdErr { [self writeToFileHandle:[NSFileHandle fileHandleWithStandardError]]; }
>
> @end

…and you'll be able to tell strings to output themselves like so:

[@"Hello, World!\n" writeToStdOut];

[@"Oh, no!  Something broke!\n" writeToStdErr];

[[self description] writeToStdOut];

-jcr_______________________________________________

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: Troubles with Bold and Italic fonts - Cocoa
  • Next by Date: Re: NSOutlineView doesn't call outlineView:shouldSelectItem: after selectRowIndexes:byExtendingSelection:
  • Previous by thread: Please allow me to introduce myself ...
  • Next by thread: Cocoaheads - Silicon Valley still needs speakers
  • Index(es):
    • Date
    • Thread