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

标签 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[],不幸的是我在这方面并不先进。谢谢

最佳答案

试试这个:

-(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
}

关于Objective-C,如何将 char[] 传递给方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10866225/

相关文章:

ios - 将值连接到 NSMutableDictionary 中的相同键

cocoa - 在谓词中使用@min

iphone - MKMapView 返回错误的用户位置

cocoa - 覆盖 NSDocument 窗口标题中的 "Edited"

c# - 为Elasticsearch日期字段提供空值

php - 使用 PHP 在 Objective-C 应用程序和 MySQL 之间进行安全通信

objective-c - 在 Objective C 中,if (object == nil) 和 if (nil == object) 之间有区别吗?

java - 类和属性 - Java

php - 在 PHP 中实现数据结构的最佳方法?

ios - 如果应用程序处于非事件状态,AFNetWorking 在 30 秒后执行 setCompletionBlock