Objective-C,如何将char []传递给方法?

时间:2012-06-02 21:52:04

标签: objective-c cocoa class

我有这个方法调用另一个方法。如何将char []传递给它而不是将char []传递给它?

- (IBAction)goThere(id)sender {

   // char hex[] = {0xFF, 0xFF, 0x15}; <-- this is what I want to pass to elseWhere
   // NSString *text = "some string";  <-- it would be cool to send other things too.

    [self elseWhere];
}

- (void)elseWhere {

char hex[] = {0xDA, 0xFF, 0x15};

...

}

理想情况下,我可以从goThere发送char [],能够根据需要重新使用char [],不幸的是我没有先进。感谢

2 个答案:

答案 0 :(得分:2)

试试这个:

-(IBAction)goThere:(id)sender {
    char hex[] = {0xFF, 0xFF, 0x15};
    [self elseWhereWithData:hex length:3];
}

-(void)elseWhereWithData:(char*)array length:(int)length {
    // array is a char array with a length of length.
    // Do stuff....strong text
}

答案 1 :(得分:0)

像这样:

-(void)method:(char[])array {
    //do something with array
}