Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Objective-c中定义自己文件中的c结构并将其作为参数传递_Objective C_C_Struct - Fatal编程技术网

如何在Objective-c中定义自己文件中的c结构并将其作为参数传递

如何在Objective-c中定义自己文件中的c结构并将其作为参数传递,objective-c,c,struct,Objective C,C,Struct,我把这个问题当作两个问题来问,因为我认为如果没有另一个问题,我不能问其中一个问题 在我的应用程序中,我有很多东西的前缀是“ND”,意思是n维的,我在我的NDVector类中有一个类似的方法: angleAtIntersectionWith: (NDVector *) vec inPlaneFirstAxis: (NSUInteger) a1 secondAxis: (NSUInteger) a2 如果你想知道的话,这个方法应该是在一个平面上找到两个向量之间的角度,也就是说,它们的两个

我把这个问题当作两个问题来问,因为我认为如果没有另一个问题,我不能问其中一个问题

在我的应用程序中,我有很多东西的前缀是“ND”,意思是n维的,我在我的
NDVector
类中有一个类似的方法:

angleAtIntersectionWith: (NDVector *) vec 
    inPlaneFirstAxis: (NSUInteger) a1 secondAxis: (NSUInteger) a2
如果你想知道的话,这个方法应该是在一个平面上找到两个向量之间的角度,也就是说,它们的两个分量由a1和a2索引。比如说
vec1角度intersection with:vec2 in PlanFirstaxis:0 secondAxis:2
将在0索引元素和2索引元素(X和Z分量)处查找
vec1
vec2
之间的角度

我想简化这个方法,使它看起来像这样:

angleAtIntersectionWith: (NDVector *) vec inPlane: (struct NDPlane *) plane
struct NDPlane{
    NSUInteger a1;    
    NSUInteger a2;
};
其中,NDPlane应为如下结构:

angleAtIntersectionWith: (NDVector *) vec inPlane: (struct NDPlane *) plane
struct NDPlane{
    NSUInteger a1;    
    NSUInteger a2;
};
就这样,这就是它所需要的。没有方法或任何东西


我想把NDPlane保存在它自己的文件中,那么我该怎么做呢?我要制作一个简单的c头文件吗?如果是,我是否正确地将其作为结构传递

是的,只需创建一个简单的.h文件来声明结构。然后在需要的地方导入.h

但是,您不希望参数中包含指针。C结构通过值传递,而不是引用。就像原始类型一样

我还建议您键入def结构,这样您就不必在使用
NDPlane
的任何地方都使用
struct