這是我想要做的。
我有一個名爲userInfo的類。我在另一個名爲LoginInfo的類中創建了這個對象的一個實例。我想保持這個instace活着,併爲所有其他類訪問,直到應用程序仍然活着...在應用程序中保持對象的活性 - 如何?
我如何實現這一目標?我讀了一些地方,我可以做到這一點與單身人士班。但我不知道他們是什麼...我是很新的cocoa..Please指南..提前
謝謝..
@interface UserInfo : NSObject {
NSString * firstName;
NSString * lastName;
NSString * uID;
NSString * password;
NSString * userType;
}
-(id)initWithFirstName:(NSString *)fname andLastName:(NSString *)lname andUID:(NSString *)userID andPassword:(NSString *)pwd andUserType:(NSString *)type;
@property (readwrite, copy) NSString * firstName;
@property (readwrite, copy) NSString * lastName;
@property (readwrite, copy) NSString * uID;
@property (readwrite, copy) NSString * password;
@property (readwrite, copy) NSString * userType;
@end
#import "UserInfo.h"
@implementation UserInfo
-(id)initWithFirstName:(NSString *)fname andLastName:(NSString *)lname andUID:(NSString *)usid andPassword:(NSString *)pwd andUserType:(NSString *)type{
self=[super init];
if (self) {
self.firstName=fname;
self.lastName=lname;
self.uID=usid;
self.password=pwd;
self.userType=type;
}
return self;
}
@synthesize firstName;
@synthesize lastName;
@synthesize uID;
@synthesize password;
@synthesize userType;
@end
這是我想要做的類單身......請指導我做什麼改變..我想使用自定義構造函數... M很抱歉把這段代碼作爲答案。但我無法在評論中得到它...
您是如何使你的代碼中的註釋不同? – 2011-02-03 10:49:33