我正在嘗試訪問目標C類中的結構。但我是 不成功。任何人都可以解釋這個類是如何調整 使其編譯和訪問成員變量?如何在objectiveC類中使用struct和union?
#import <Foundation/Foundation.h>
enum ACCOUNT_TYPE {
SAVINGS,
LOAN,
FIXED_DEPOSIT
};
struct SavingsData {
NSMutableString* accountName;
NSMutableString* accountType;
NSMutableString* balance;
NSMutableString* currency;
};
struct LoanData {
NSMutableString* accountName;
NSMutableString* balance;
};
struct FixedDepositData {
NSMutableString* accountName;
NSMutableString* depositAmount;
NSMutableString* roi;
};
union AccountData {
struct SavingsData *savingsData;
struct LoanData *loanData;
struct FixedDepositData *fixedDepositData;
};
@interface Account : NSObject {
NSMutableString* accountId;
enum ACCOUNT_TYPE type;
union AccountData *accountData;
}
@property (nonatomic, assign) NSMutableString* accountId;
@property (nonatomic, assign) enum ACCOUNT_TYPE type;
@property (nonatomic, assign) union AccountData *accountData;
我試圖使用(。)運算符訪問變量。我想我必須使用accountData-> savingsData-> accountName。編譯。尚未在運行時嘗試...即將開始。感謝您的反饋如此之快。它有助於。 – Satish