[NSString dataUsingEncoding:]

sometimes you have to look at the source object, not the destination (in fact 
usually, I'd say).

Also, in this case, [NSData initWithString:] would lack the information needed 
to perform the conversion - you need to pass in what encoding you require.

--Graham




On 17 May 2014, at 9:46 am, William Squires <wsqui...@satx.rr.com> wrote:

> Why doesn't NSData have a +[NSData dataWithString:(NSString *)] or -[NSData 
> initWithString:(NSString *)] method? i.e. how do I convert the contents of an 
> NSString object into an NSData object? Why? Because -[NSFileHandle 
> writeData:(NSData *)] takes an NSData object, not an NSString object. 
> Arrrgghhhh. :(
>  Also, how come NSFileHandle doesn't have a -[NSFileHandle 
> readFileWithSeparator:(NSString *)] method so one can read in only chunks of 
> a file (of varying size, such as CSV records, or lines in a text file, 
> separated by \n, as opposed to a fixed size, which could be accomplished with 
> -[NSFileHandle readDataOfLength:(NSUInteger)] instead), instead of having to 
> read in the whole thing? Especially on iOS, where memory space is at a 
> premium!
>  This seems like a major oversight to me... unless maybe there's a class 
> which provides a higher-level of abstraction, such as NSTextFileHandle? Yeah, 
> I can drop down to the C-level fopen(), fread(), fwrite(), fclose() etc... 
> functions, but I'm looking for an OO-way to do this.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to