重複の可能性:
他のクラスのオブジェクトにアクセスできません
私はobjective-cの構文と機能の理解を深めるために小さなプロジェクトに取り組んできましたが、自分のプロジェクトで立ち往生していて、答えを見つけることができません。
最初に2つのクラスがあり、メインのクラスで他のクラスのオブジェクトを宣言して、他のクラスの関数を使用できるようにしました。これが私がそれをした方法です(私はちょうど私が必要だと思ったものを書きました:
.h of my main class
import myOtherClass
@interface PkmViewController : UIViewController
@property Pokemon * nomDePokemon;
.m of my main class
import myOtherClass
@synthesize nomDePokemon;
int nbDef = [nomDePokemon calculerUnNombrePourLaDefense];
.h of my other class
@interface Pokemon : NSObject
@property int defencePoints;
-(int)calculerUnNombrePourLaDefense;
.m of my other class
@synthesize defencePoints;
-(int)calculerUnNombrePourLaDefense
{
int nombrerandom = arc4random() % 45;
return nombrerandom;
}
メインクラスにブレークポイントを設定して、関数から取得された数値を確認すると、常に0になります。このセクションを他のクラスに配置すると機能しますが、スキルを向上させるために別のクラスに保持したいと思います。 。誰かが私にそれを行う方法を説明できますか?