Re: NSData weirdness...
Re: NSData weirdness...
- Subject: Re: NSData weirdness...
- From: Andy Lee <email@hidden>
- Date: Fri, 21 Jun 2002 02:21:56 -0400
At 8:22 PM -0700 6/20/02, Warwick Hall wrote:
NSRange range = {0, 100};
NSData* contents = [NSData dataWithContentsOfMappedFile :
[[[NSBundle mainBundle] resourcePath] stringByAppendingString :
@"/LevelData.data"]];
NSData* data = [contents subdataWithRange : range];
NSLog(@"%s", [data bytes]);
Ditto to what's already been said about what "%s" expects and what
you're giving it.
I would also suggest you try the following replacement for your NSLog
line and see what happens:
NSLog(@"%@", data);
The "%@" in the format string expects an Objective-C object pointer
(unlike "%s", which expects a C string pointer). When the format
string is expanded, it will contain a textual representation of the
object. Exactly what that means depends on the class of the object.
If you know your data is plain text, you can convert it to an
NSString object as follows:
// ...
NSData* data = [contents subdataWithRange:range];
NSString *s =
[NSString stringWithCString:([data bytes] + range.location)
length:range.length];
NSLog(@"my data as a string: %@", s);
HTH,
--Andy
_______________________________________________
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.