非常基本的objective-c问题
我写了一个简单的程序来理解objective-c是如何工作的。这个程序就是易经,一种基于六行回应的古代占卜,在发行三枚硬币六次后计算,然后建立一个卦,这就是回应 我被困在这一点上,我相信有简单的解决办法。这就是我定义线条的方式,我知道这不是最好的设计,但我正在尝试使用尽可能多的技术。 假设你发射一枚硬币,它可以是3或2,这取决于侧面,三枚硬币的结果可能是6,7,8,9非常基本的objective-c问题,objective-c,arrays,struct,Objective C,Arrays,Struct,我写了一个简单的程序来理解objective-c是如何工作的。这个程序就是易经,一种基于六行回应的古代占卜,在发行三枚硬币六次后计算,然后建立一个卦,这就是回应 我被困在这一点上,我相信有简单的解决办法。这就是我定义线条的方式,我知道这不是最好的设计,但我正在尝试使用尽可能多的技术。 假设你发射一枚硬币,它可以是3或2,这取决于侧面,三枚硬币的结果可能是6,7,8,9 /** * identifying a coin */ typedef enum { head=3, tai
/**
* identifying a coin
*/
typedef enum {
head=3,
tail=2
} Coin;
/**
identify a line, three coins with a side value of
2 and 3 can result in 6,7,8,9
*/
typedef enum {
yinMutable=tail+tail+tail, // 6 --> 7
yang=tail+tail+head, // 7
yin=head+head+tail, // 8
yangMutable=head+head+head // 9 --> 8
} Line;
/**
The structure of hexagram from bottom "start" to top "end"
*/
typedef struct {
Line start;
Line officer;
Line transit;
Line minister;
Line lord;
Line end;
} Hexagram;
我在这种设计中遇到的第一个问题是在每一行六边形中指定一个值。第一次发射应在start中填充值,第二次发射应在start中填充值…等等。
但可以很容易地解决一个开关盒…虽然我不喜欢它
1) 第一个问题:我想知道是否有类似javascript或类似c的函数
foreach(Hexagram中的属性)允许我按声明顺序浏览属性,这将解决我的问题
2) 第二个问题:作为一种替代方法,我使用了一个行数组:
Controller.m
....
Line response[6]
....
-(id) buildHexagram:... {
for(i =0.....,i++).....
response[i]=throwCoins;
// I omit alloc view and the rest of the code...then
[myview buildSubview:response];
}
----------------------
subView.m
-(id) buildSubView:(Line[]) reponse {
NSLog(@"response[0]=%o",[response objectAtIndex[0]]); <--- HERE I GOT THE ERROR
}
Controller.m
....
线路响应[6]
....
-(id)构建卦:。。。{
对于(i=0…,i++)。。。。。
响应[i]=通过连接;
//我省略了alloc视图和其余的代码…然后
[myview buildSubview:响应];
}
----------------------
子视图.m
-(id)buildSubView:(第[]行)响应{
NSLog(@“response[0]=%o”,[response objectAtIndex[0]]);您已经创建了一个C行数组,以访问需要使用C样式数组访问器的元素
所以不是
[response objectAtIndex[0]]
使用
嗨…这很有效,但是我还有一个基本问题。在接收方法中,我想做一个作业:行响应[6];
response[0]