开发者

how to call a function of a same class from other functions of the same class-Objective C

开发者 https://www.devze.com 2023-03-04 20:15 出处:网络
But i\'m getting errors when declaring like this. @implementation data -(void)SwapEndian:(uint8_t*)pData withBOOLValue:(bool)bIsAlreadyLittleEndian

But i'm getting errors when declaring like this.

@implementation data

-(void)SwapEndian:(uint8_t*)pData withBOOLValue:(bool)bIsAlreadyLittleEndian
{
data* datas = [data alloc];
[datas swapEndians:(uint8_t)&pData[nIndex] withSize:(sizeof(uint32_t));  
}

-(void)swapEndians:(uint8_t*)pData withnByteSize:(int const)nByteSize
{
    NSLog(@"swapEndians!!");
}

@end

How to call a function from other function i开发者_如何转开发nside the same class?


You can use self keyword to achieve this.

[self yourFunctionName];


First things first:

data* datas = [data alloc]; // Where is your init? Don't use un-initialized objects!
[datas swapEndians:(uint8_t)&pData[nIndex] withSize:(sizeof(uint32_t));

Second thing:
If the method you are trying to call is the second one from you code, you have a typo in the selector! That line should read:

[datas swapEndians:&pData[nIndex] withnByteSize:sizeof(uint32_t)];

Third thing:
You send messages to yourself by using self.


First of all class name should start with capital letter, here is I think you are tying to do

    @implementation Data //changed it just naming convention 

    -(void)swapEndian:(uint8_t*)pData withBOOLValue:(bool)bIsAlreadyLittleEndian
      {
         [self swapEndians:(uint8_t)&pData[nIndex] withSize:(sizeof(uint32_t));  
      }

    -(void)swapEndians:(uint8_t*)pData withnByteSize:(int const)nByteSize
      {
        NSLog(@"swapEndians!!");
      }

    @end
0

精彩评论

暂无评论...
验证码 换一张
取 消