Re: BOOL array
Re: BOOL array
- Subject: Re: BOOL array
- From: dreamcat7 <email@hidden>
- Date: Thu, 11 Sep 2008 12:32:24 +0100
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;
_______________________________________________
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