using NSMutableDictionary with values
using NSMutableDictionary with values
- Subject: using NSMutableDictionary with values
- From: Candide Kemmler <email@hidden>
- Date: Tue, 3 Jul 2001 18:52:52 +0200
Hi again !
Now, I've been told several times that Foundation provided exquisite
mechanisms for dealing with data structures. I'm not yet comfortable
enough to be 100% sure of the best way to get my job done with
Objective-C.
So I'm receiving data from the wire, not knowing how much of it (i.e.
can't declare fixed arrays). The data is meant to be stored in a
Dictionary. NSMutableDictionary accepts only objects. I want to
associate int values with an array of structs (or Objective-C objects,
but I'm a bit shy with these...). For now, I have a no-op code that goes
like this:
strokes = [ [ NSMutableDictionary alloc ] init ];
len = readInt ( bufferHandle );
NSLog ( @"about to read %d stroke entries", len );
for ( i=0; i<len; i++ ) {
fakeInt = readInt ( bufferHandle ); // key value
len2 = readInt ( bufferHandle );
// now comes the array of structs
for ( j=0; j<len2; j++ ) {
fakeInt = readInt ( bufferHandle );
fakeInt = readInt ( bufferHandle );
fakeInt = readInt ( bufferHandle );
fakeInt = readInt ( bufferHandle );
}
}
The struct is defined like so:
struct roadStroke {
int width;
int red;
int green;
int blue;
};
(I would've preferred to use an NSColor *, but that leads to strange
compilation errors, not recognizing the "@" character somewhere...)
I think I know the roadStroke struct's going to be wrapped in an NSValue
object. From the provided docs, it's not clear to me wether the value
must be provided by value or by reference...
Please tell me what's the best way to proceed.
Thanks for all your precious help, folks !
Candide