Re: NSData Deprecations
Re: NSData Deprecations
- Subject: Re: NSData Deprecations
- From: Chris Kane <email@hidden>
- Date: Wed, 25 Sep 2002 18:25:28 -0700
On Tuesday, September 17, 2002, at 10:49 AM, Isaac Sherman wrote:
I came across a deprecated function that I use extensively; NSData's
deserializeIntAtIndex:, and it's sister function, NSMutableData's
serializeIntAtIndex:. It appears my only alternative is to rewrite
several
large blocks of code to use the NSPropertyList thingie instead, which
seems
overkill to me (considering that several of my uses are just for
encoding a
single number in a temporary file). The thing that pisses me off is
that
Apple didn't even ask my permission! Anyway, are there any other
alternatives?
Those methods aren't really doing much for you -- you can use
replaceBytesInRange:withBytes: yourself, like this for the
serializeInt:atIndex: type of operation:
[myData replaceBytesInRange:NSMakeRange(location, 4) withBytes:&value];
and the reverse for reading:
int value;
memmove(&value, [myData bytes] + location, 4);
Lest you think those "4" constants are a mistake, they aren't. These
methods read and write ints as 4 bytes, and have to forever (or as long
as the API exists) for compatibility; if int were larger, then these
methods would read/write crap or have to truncate the int parameter or
something. Nobody ever said this was a good API.
If this data is going to go out to a file, for robustness you'd
probably want to byte order those values to, say, big endian before or
after (respectively) using the value variable above. In case you ever
wanted to read the file on Windows on a PC, for example.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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.