• 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: Look at NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Look at NSData


  • Subject: Re: Look at NSData
  • From: Marco Binder <email@hidden>
  • Date: Sat, 12 Apr 2003 18:16:38 +0200

1) there is no point in initializing an NSData object with only a length of 4080 bytes if you dont specify which 4080 bytes to put in there. This coud be done with the appropriate init-method. Straight from the docs (which you really might want to read for basic questions like this one- tip: also have a look at the "programming topics"):

- (id)initWithBytes:(const void *)bytes length:(unsigned)length

Initializes a newly allocated data object by adding to it length bytes of data copied from the buffer bytes. Returns self.

See Also: + dataWithBytes:length:, - initWithBytesNoCopy:length:, - initWithBytesNoCopy:length:freeWhenDone:

2) I told you there is no point in just initializing NSData with a length. And this is because you CANNOT CHANGE IMMUTABLE OBJECTS after having created them. If you want to create a data object that you can fill with data or alter the contained data after creation, you should, no you HAVE TO use NSMutableData. Again straight from the docs (which really, really have to read):

+ dataWithCapacity:
Returns an NSMutableData with enough allocated memory to hold a specified number of bytes.

+ dataWithLength:
Returns an NSMutableData that contains a specified number of 0-filled bytes.

Take care and have alot of fun coding,

MArCo


Am Samstag, 12.04.03 um 18:05 Uhr schrieb Peter Karlsson:

Hi!

And thanks for you answer :-)

Yea, I see now that I only have 1 byte in myData2 (I checked it with lenght), so I have 2 questions for you.

1 - How do I initialize myData2 to be 4080 bytes in size? (yea, it's always that size)

2 - How do I write to different positions in myData2? For example: I have a loop and the first lap I want to write a byte to offset 0 in myData2, the next lap I want to write a byte to offset 1 and so on.

Peter

From: Marco Binder <email@hidden>
To: "Peter Karlsson" <email@hidden>
CC: email@hidden
Subject: Re: Look at NSData
Date: Sat, 12 Apr 2003 17:57:05 +0200

Well, my guess would be that the message tells you the truth! There is only 1 byte in myData2, therefore the index of 1 is not valid. Check how you initialize myData2... and you should never put a hard coded upper limit (4080) into your loop if you arnt sure how long the data actually is...


Am Samstag, 12.04.03 um 13:10 Uhr schrieb Peter Karlsson:

myData is declared like this:
NSData *myData = [NSData dataWithContentsOfFile:thePath];

myData2 is declared like this:
NSData *myData2;

When trying this code I get a error message saying:
*** -[NSConcreteData getBytes:range:]: location 1 exceeds data length 1

// check to see if myData2 holds the right values
for (i = 0; i < 4080; i++)
{
myRange.location = i;
[myData2 getBytes:&buffer1 range:myRange];
NSLog(@"X", buffer1);
}

But looking at myData works. What's the problem here?

Peter

From: "Peter Karlsson" <email@hidden>
To: email@hidden
Subject: Look at NSData
Date: Sat, 12 Apr 2003 06:36:14 +0000

Dear list!

I have a NSData object and wonder how I can look at all the bytes inside it with the help of NSLog?

Example: Lets say I have 1000 bytes in the NSData object and I want to look at all the bytes in a loop, how?

Peter

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail
_______________________________________________
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.

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail
_______________________________________________
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.


--
|\ /| email@hidden http://www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________


_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail


--
|\ /| email@hidden http://www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.

  • Prev by Date: Re: How to clear an NSImage
  • Next by Date: Drawing into an NSView
  • Previous by thread: Re: Look at NSData
  • Next by thread: Make the action of a NSMenuItem, which has a subMenu, to work
  • Index(es):
    • Date
    • Thread