我想在方法中传递一个结构,所以我可以改变它的值,但我不太确定它的语法:
struct qsTracker { int points; BOOL flagged; } myCurrentQs; [self calculateScore:myCurentQs]; -(void) calculateScore:(struct qsTracker) currentQs { currentQs.points++; currentQS.flagged = YES; }
显然,currentQs没有看到任何变化.任何帮助将非常感激.
您应该传入指向结构的指针,而不是结构本身:
-(void) calculateScore:(struct qsTracker *) currentQs { currentQs->points++; currentQS->flagged = YES; }
然后:
[self calculateScore:&myCurentQs];
因为currentQs
现在是指针,所以在方法内部进行的更改将反映在方法之外.