• 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
NSData weirdness...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSData weirdness...


  • Subject: NSData weirdness...
  • From: Warwick Hall <email@hidden>
  • Date: Thu, 20 Jun 2002 20:22:18 -0700

Dear All,

I have written an experiment class to play around with Cocoa and NSBundles and so on, and I have a mind numbing question about NSData usage.

Below is a Level.m file listing that is set to be my NSApp delegate (set in Interface Builder).

// START FILE CONTENTS

#import "Level.h"

@implementation Level

- (void) applicationDidFinishLaunching : (NSNotification*) event
{
NSRange range = {0, 100};
NSData* contents = [NSData dataWithContentsOfMappedFile :
[[[NSBundle mainBundle] resourcePath] stringByAppendingString :
@"/LevelData.data"]];
NSData* data = [contents subdataWithRange : range];

NSLog(@"%s", [data bytes]);

//
// Quit the application...
//
[NSApp terminate : self];
}

@end

// END OF FILE CONTENTS

The problem is this: the subdataWithRange: message does not seem to work. You see the LevelData.data file in the app bundle is approx 60K in length. But when I view the output from the NSLog() line, instead of just the 0..100 byte range I get the entire file contents. Arghh!

Another problem was that I had mysterious info.plist type stuff appended after the contents NSData* variable when I was using the [NSData dataWithContentsOfFile:] message. The NSLog() method would spit out the entire file contents (instead of the subrange) and append mumbo jumbo like:



Current/Frameworks/HIToolbox.framework/HIToolbox</string>
<string>_RegisterStandardEventClasses</string>
</array>
</dict>
<key>Gestalt</key>
<dict>
<key>afps</key>
<integer>1879048256</integer>

... and so on and so forth [lots of .plist stuff here]...

<key>mnam</key>
<array>
<string>/System/Library/Frameworks/CoreServices.framework/Versions/Current/
Frameworks/OSServices.framework/OSServices</string>
<string>_OSS_InstallGestaltSelectors</string>
</array>

... and so on and so forth [lots of .plist stuff here]...

</dict>
</dict>
</plist>


And I can assure all and sundry that this stuff is *NOT* in the LevelData.data resource file. And when I switched to the [NSData dataWithContentsOfMappedFile:] message instead, the info.plist stuff went away. However the Cocoa documentation says it is normally better to use [NSData dataWithContentsOfFile:] message because the Mapped message requires that the file be there at all times while in use.

Does anyone have a clue why this is all happening to me?

Thankx an NSBundle!
titaniumskin

"Imagination is more important than knowledge." - Albert Einstein
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSData weirdness...
      • From: Andy Lee <email@hidden>
    • Re: NSData weirdness...
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: Re: Outputting an unsigned long long
  • Next by Date: Re: NSData weirdness...
  • Previous by thread: Re: Outputting an unsigned long long
  • Next by thread: Re: NSData weirdness...
  • Index(es):
    • Date
    • Thread