Re: BOOL array
Re: BOOL array
- Subject: Re: BOOL array
- From: Jean-Daniel Dupas <email@hidden>
- Date: Thu, 11 Sep 2008 14:08:49 +0200
Le 11 sept. 08 à 13:32, dreamcat7 a écrit :
Yes the NSMutableData needs this category method then it work.
@interface NSMutableData (charArray)
- (char*)char;
@end
@implementation NSMutableData (charArray)
- (char*)char
{
char * foo = self.mutableBytes;
return foo;
}
@end
+ (NSMutableData*)defaultOptions
{
NSMutableData* defaultOptions = [NSMutableData dataWithLength:20];
[defaultOptions char][03] = 0xFF;
[defaultOptions char][11] = 0xFF;
[defaultOptions char][19] = 0xFF;
// [defaultOptions char][] = YES;
NSLog(@"%@:%s defaultOptions = %@", [self class], _cmd,
defaultOptions);
return [[defaultOptions retain] autorelease];
}
You can also declare your index numbers as an enum to make them easy
to remember
enum MyOptions
{
MyOptionsFirstOption = 00,
/* declare any more BOOL options */
MyOptionsNinteenthOption = 18,
MyOptionsLastOption = 19,
MyOptionsLength = 20,
};
which makes the [03] into [MyOption]
+ (NSMutableData*)defaultOptions
{
NSMutableData* defaultOptions = [NSMutableData
dataWithLength:MyOptionsLength];
[defaultOptions char][MyOptionsFirstOption] = YES;
[defaultOptions char][MyOptionsNinteenthOption] = YES;
// All other options are (signed char)0x00 = (BOOL)NO;
NSLog(@"%@:%s defaultOptions = %@", [self class], _cmd,
defaultOptions);
return [[defaultOptions retain] autorelease];
}
And probably will also want to write kvc-compliant accessor methods
(for the ones which you would like exposed in your class' public
interface)
- (BOOL)myFirstOption;
- (void)setMyFirstOption:(BOOL)theBool;
That's fine if you love to reinvent the wheel, but that exactly the
interface provided by CFMutableBitVector.
CFBitVectorCreateMutable()
CFBitVectorSetBitAtIndex()
CFBitVectorGetBitAtIndex()
And it probably does it better as it will not waste 7 bits for each
option.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden