• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSData weirdness...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >NSData weirdness... (From: Warwick Hall <email@hidden>)

  • Prev by Date: Re: Outputting an unsigned long long
  • Next by Date: Re: Outputting an unsigned long long
  • Previous by thread: Re: NSData weirdness...
  • Next by thread: Re: NSData weirdness...
  • Index(es):
    • Date
    • Thread