2012-09-08 13 views
0

訪問值我呼籲A這是一個接口,可以節省一些值float類型:從不同的接口

float x,y; 

,並在.m文件initilizing他們:

.h文件中聲明 X = 56.4; y = 666.3;

如何從另一個界面訪問這些值?我想這樣做:

float MyX = A.x; 
float myY = A.y; 
+0

使用[properties](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html)。 – Adam

回答

0

你應該確實使用屬性。屬性'暴露'你的變量並自動生成一對getter/setter方法。在您的.h文件中,你可以聲明如下:

@property float x; 
@property float y; 

而且你應該在你的.m文件合成則:

@synthesize x; 
@synthesize y; 

然後你就可以訪問的變量,你想要的方式;)