0

I am new to Objective C. I am porting the cpp code to Objective C.

pMsg->TxCreateImage((INT8U*)m_cData.m_abTxMsgImage,m_cData.m_nTxImageSize);

TxCreateImage((INT8U*)pData,int uLen)
{
 func definition;
}

TxCreateImage is a function call. m_cData is the object of another class.

Is this Objective C equivalent correct.

Data* pMsg = [[Data alloc]init];
Ds* m_cData;

[pMsg TxCreateImage:(int *)[m_cData m_abTxMsgImage] :(int)[m_cData m_nTxImageSize]];

- (void)TxCreateImage:(int*)pData :(int)uLen
{
 //func definition;
}

I am getting exceptions like,

-[Packet m_nTxImageSize]: unrecognized selector sent to instance 0x100831e00
2011-05-04 17:11:07.756 Test-packetCreation[4633:a0f] *** Terminating app due to uncaught 
exception 'NSInvalidArgumentException', reason: '-[Ds m_nTxImageSize]: unrecognized 
selector sent to instance 0x100831e00'
Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152
Angus
  • 12,133
  • 29
  • 96
  • 151
  • Also, in objective-c we tend to put descriptions in our method signatures. I.e. `[object doSuperCoolMethodUsingInt:i withString:name];` - it just makes the code more readable :) – Aurum Aquila May 04 '11 at 11:57
  • This would not compile. Did you type it in the browser or is this actually what you have? eg [m_cData m_nTxImageSize)] – hooleyhoop May 04 '11 at 12:02
  • @fakeAccount22:Sorry I mistakenly put the ')' while editing. – Angus May 04 '11 at 12:09

2 Answers2

2

You need to initialize m_cData for one. And i'm not so sure about passing a pointer to integer; If that doesn't work try looking at the return type of m_nTxImageSize;

Unrecognised selector means it can't access/see the method called by m_nTxImageSize

Radu
  • 3,434
  • 4
  • 27
  • 38
  • sorrry i made a mistake here m_abTxImage and m_nTxImageSize are variables.How to pass variables of one class to another. – Angus May 04 '11 at 12:08
1

Huge difference betwwen Objective-C and C++:

=> Message send are late bound.

You should get the habit of having does kind of error. Look in you Ds class definition and see if you have an accessor -m_abTxMsgImage. Remeber that all instance variable (memeber for C++ guys) are protected.

If you want to make it public you have to use the @public directive. see here

Also the naming of your method -TxCreateImage:: is not the best way to of nameing method in objective-c.

Prefer something like -createImageText:size:

For accessors set method are named setMyInstVar and get method myInstVar. Also it is not common to add the m_ to instance variable.

Accessor can be create automaticaly using the @synthesize directive which follow the convention I told you above.

Community
  • 1
  • 1
mathk
  • 7,973
  • 6
  • 45
  • 74