我正在寫一個簡單的遊戲,並認爲它會更容易使用結構。但是,我不能聲明需要結構的方法。使用struct Objective-C方法
我怎樣才能使用一個結構作爲參數到一個Objective-C方法並獲得結構的對象返回?
//my structure in the .h file
struct Entity
{
int entityX;
int entityY;
int entityLength;
int entityWidth;
int entityType;
bool isDead;
};
//And the methods i'm trying to use
-(BOOL)detectCollisionBetweenEntity:Entity ent1 andEntity:Entity ent2;
-(struct Entity)createEntityWithX:int newEntityX andY:int newEntityY, withType:int newEntityType withWidth:int newEntityWidth andLength:int newEntityLength;
如果您打算使用C數據結構,我建議您熟悉一下如何管理C語言中的內存以及指針如何工作。這個話題太大而無法涵蓋在SO問答中。你的其他選擇是堅持使用Objective-C,這可能不會讓你感到困惑。 – pmdj