iOS typedef NS_ENUM 与 NSString

 

 

//在头文件中声明

typedef NS_ENUM(NSUInteger, TransactionState) {
    TransactionOpened,
    TransactionPending,
    TransactionClosed,
};

extern NSString * NSStringFromTransactionState(TransactionState state);

 

//在.m文件中实现

NSString * NSStringFromTransactionState(TransactionState state) {
  switch (state) {
    case TransactionOpened:
      return @"Opened";
    case TransactionPending:
      return @"Pending";
    case TransactionClosed:
      return @"Closed";
    default:
      return nil;
  }
}

 

参考资料:http://nshipster.com/c-storage-classes/

posted @ 2016-04-10 20:27  Ficow  阅读(5045)  评论(0编辑  收藏  举报