相关疑难解决方法(0)

将objective-c typedef转换为其等效字符串

假设我在.h文件中声明了一个typedef:

typedef enum {
  JSON,
  XML,
  Atom,
  RSS
} FormatType;
Run Code Online (Sandbox Code Playgroud)

我想构建一个将typedef的数值转换为字符串的函数.例如,如果邮件[self toString:JSON]已发送; 它会返回'JSON'.

该函数看起来像这样:

-(NSString *) toString:(FormatType)formatType {
  //need help here
  return [];
}
Run Code Online (Sandbox Code Playgroud)

顺便说一句,如果我尝试这种语法

[self toString:FormatType.JSON];
Run Code Online (Sandbox Code Playgroud)

要将typedef值传递给方法,我收到一个错误.我错过了什么?

c enums typedef objective-c

138
推荐指数
9
解决办法
12万
查看次数

标签 统计

c ×1

enums ×1

objective-c ×1

typedef ×1