目标C方法签名可以指定枚举类型吗? [英] Can an objective C method signature specify an enum type?

查看:73
本文介绍了目标C方法签名可以指定枚举类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"VoiceName"是一个枚举,声明如下:

"VoiceName" is an enum, declared like this:

enum VoiceName {
 PAD_RHYTHM,
 PAD_RHYTHM2,
 PAD_RHYTHM3,
 PEEPERS,
 ATMOSPHERE,
 IMPULSE,
 FAST_PULSE,
 HAIRYBALLS_PADS,
 KICK
};

编译器似乎不喜欢我在这样的方法签名中使用它:

The compiler doesn't seem to like me using it in a method signature like this:

-(void)pulseFiredWithSamplePosition:(float)position from: (VoiceName) voiceName;

它告诉我期望的')'在'VoiceName'之前.这是怎么回事?

It tells me expected ')' before 'VoiceName'. What's going on here?

推荐答案

在不指定枚举的情况下,不能像这样裸露"使用它:

You can't use it "bare" like that without also specifying that it's an enum:

-(void)pulseFiredWithSamplePosition:(float)position from: (enum VoiceName) voiceName;

应该工作.如果要避免这样指定,可以输入defdef:

should work. If you want to avoid specifying it like that, you can typedef it:

typedef enum _VoiceName {
    PAD_RHYTHM,
    ....
} VoiceName;

那么您将只能使用VoiceName作为参数类型.

then you'll be able to use just VoiceName as the argument type.

这篇关于目标C方法签名可以指定枚举类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆