Re: [NSMutableData resetDataRangeTo:(NSRange)range];
Re: [NSMutableData resetDataRangeTo:(NSRange)range];
- Subject: Re: [NSMutableData resetDataRangeTo:(NSRange)range];
- From: Carl Hoefs <email@hidden>
- Date: Mon, 14 Jul 2014 11:48:07 -0700
On Jul 14, 2014, at 11:35 AM, Ben Kennedy <email@hidden> wrote:
> On 14 Jul 2014, at 11:30 am, Carl Hoefs <email@hidden> wrote:
>
>>> [bigMData replaceBytesInRange:NSMakeRange(0,0) withBytes:newBytesPtr length:1024];
>>
>> Wow, that's damn clever! My thinking is so clunky. It never would have occurred to me that NSMutableData could expand (0,0) into (0,1024) out of thin air! Awesome!
>
> Well, it's basically the inverse of your first question, for which Matt Gough already provided the answer.
>
> NSMutableData's method is well designed and well named because it does exactly as it implies: replaces some range of data (whatever size) with another chunk of data (whatever size).
>
> -ben
>
Yes, I guess it's the semantics that threw me. I was attempting to "insertBytesInRange" not "replaceBytesInRange", so I had it in my mind that the one couldn't do the other. But that's the whole purpose of the NSRange. Very cool.
-Carl
_______________________________________________
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