在.h文件中定义如下:
@interface ransactionStateMachine : NSObject
typedef NS_ENUM(NSUInteger, TransactionState) {
TransactionOpened,
TransactionPending,
TransactionClosed,
};
//加上extern 在外不直接调用 不加 需要导入头文件
extern NSString * NSStringFromTransactionState(TransactionState state);
@end
.m文件中定义如下:
@implementation ransactionStateMachine
NSString * NSStringFromTransactionState(TransactionState state) {
switch (state) {
case TransactionOpened:
return @"Opened";
case TransactionPending:
return @"Pending";
case TransactionClosed:
return @"Closed";
default:
return nil;
}
}