Re: newbie defines and NSString problem
Re: newbie defines and NSString problem
- Subject: Re: newbie defines and NSString problem
- From: Ondra Cada <email@hidden>
- Date: Thu, 11 Mar 2004 21:25:18 +0100
Ken,
On Thursday, Mar 11, 2004, at 18:22 Europe/Prague, Ken Hawkins wrote:
thanks for all the help. does this look like the LONG way around to
write data to a file to anyone else?
Very much so.
NSString *str = COPYRIGHT_MARKER;
unichar *buff;
[str getCharacters:buff];
NSData *data = [NSData dataWithBytes:buff:[str length]];
if(data == nil)
{
[log toLog:self:kLOG_ERROR:@"writeCopyright failed could not retrieve
a copyright marker"];
[log toLog:self:kLOG_OBJECT_DEBUG:@"-writeCopyright exit-"];
return NO;
}
/* write the COPYRIGHT_MARKER */
[pfhBMD writeData:data];
btw 'pfhBMD' is a NSFileHandle pointer type.
Functionally equivalent would be
NSString *str=COPYRIGHT_MARKER;
if (!str) { // note: without knowing your app it's hard to say, but...
REPORT_ERROR // ...it would seem more appropriate to raise an...
return NO; // ...exception at this level
}
[pfhBMD write
Data:[str dataUsingEncoding:NSUnicodeStringEncoding]];
To be frank, I cannot imagine any shorter way (unless you want to
define your COPYRIGHT_MARKER directly as a data instead as a string).
and one more ? is there a nice OutputStream available? i only see
NSOutputStream that appears to write only uint8_t * information. are
there any out there that handle the formating of data types so i can do
things like writeInt, writeBOOL, etc?
Check NSCoder and all its merry fellows.
---
Ondra Hada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.