0

iPhoneのプログラミングは初めてです。私のプロジェクトでenumは、ヘッダーファイルに次のものがあります。

enum SelectionType
{

    BookSelection,
    StartChapter,
    EndChapter
}SType;

私のプロジェクトでは、私enumが今持っているものを知りたいです。そのために、次のことを試しましたが、うまくいきません。

NSLog(@"stype is %c",SType);

で列挙型を取得するには、どの書式指定子を使用すればよいNSLogですか?

4

3 に答える 3

2

あなたはそれを自分でしなければならないでしょう。C には、この種のリフレクション機能がありません。使用できる関数は次のとおりです。

const char *STypeName(SType t)
{
    switch (t) {
    case BookSelection: return "BookSelection";
    case StartChapter: return "StartChapter";
    case EndChapter: return "EndChapter";
    default: return NULL;
    }
}

次に、関数SelectionTypeNameを呼び出して名前を取得できます。

SType stype = ...;
NSLog(@"stype = %s", STypeName(stype));
于 2012-06-29T05:03:25.493 に答える
0
enum SelectionType {

BookSelection==0,//system provide the default value 0 for first enum then increase by one.
StartChapter==1,
EndChapter==2
}SType;
//then you check with 

if(sType==0)
  {
 //do something
}


else if(sType==1)
{

}

else
{

}
//you can use 
NSLog(@"Enum number=%i",sType);
于 2012-06-29T04:59:45.450 に答える
0

enumは基本的にintデータ型です。%d形式指定子を使用する必要があります。

于 2012-06-29T04:59:56.910 に答える