Reputation: 755
I could not use the pData[4096] to pass it to the other function from main.
data.m
------
@implementation data
static int msgID;
static char pData[4096]="\0";
+ (void)initialize
{
//some initialisations
msgID =123;
}
-(void)SwapEndian:(uint8_t*)pData withBOOLValue:(BOOL)bIsAlreadyLittleEndian
{
NSLog("%s %s",pData,bIsAlreadyLittleEndian);
}
@end
main.m
-------
[dat SwapEndian:dat.pData withBOOLValue:TRUE];
I am getting pData undeclared. As pData is declared as static inside the Data
implementation i tried with dat.pData to pass it from main.But when i do it i am getting
Request for member 'pData' with BOOL value TRUE is not a structure or union.
Upvotes: 1
Views: 96
Reputation: 119144
It is difficult to determine what the code is supposed to do, but here is how to create an Objective-C object that holds an integer identifier and a 4096-character array. Please note that this sort of thing is usually discouraged. Unless you have a really specific reason for using int
and char[]
, the identifier should be NSInteger
and the data should be an NSData
or NSString
object.
I have also used some of the "standard" naming conventions. If you are writing Cocoa code, it helps to drink a lot of the Kool-Aid.
Message.h:
@interface Message : NSObject
{
int identifier;
char data[4096];
}
@property (nonatomic, assign) int indentifier;
@property (nonatomic, readonly) char * data;
- (void)swapEndian:(BOOL)flag;
@end
Message.m:
@implementation Message
@synthesize identifier;
@synthesize data;
- (id)init
{
if ((self = [super init]) == nil) { return nil; }
identifier = 0;
data[0] = '\0';
return self;
}
- (void)swapEndian:(BOOL)flag
{
NSLog(@"%s %d", data, flag);
}
@end
main.m:
#import "Message.h"
...
Message * message = [[[Message alloc] init] autorelease];
message.identifier = 123;
[message swapEndian:YES];
Upvotes: 1