如何在不同的类中使用int

时间:2012-09-27 08:46:44

标签: objective-c xcode

//class1

competitionSettingsViewController.m

int *myint;

// in some void I made.
myint = 7;

//class2
competitionViewcontroller.m

#import "competitionSettingsViewController.m" 

int *myextraint = 0;

competitionSettingsViewController a = [[competitionSettingsViewController alloc]........]
myextraint = a.myint;

1 个答案:

答案 0 :(得分:1)

您可以使用property,如下所示:

@interface MyObject : NSObject
@property int myInt;
@end

然后您可以按如下方式访问它:

MyObject mo        = [[MyObject alloc] init];
int myExtraInt     = mo.myInt; 
int myAltExtraInt  = [mo myInt];