简体   繁体   中英

Assigning to enum value to incompaitable type int

I am using the c++ library. so i converted my .m file to .mm file .

Now what happens i am not able to set the enum value.

See Enum

 typedef enum{
    ImageSourceTypeCamera,
    ImageSourceTypePhotoLibrary,
    ImageSourceTypeNone
  }
ImageSourceType;

// Property

@property(nonatomic,assign) ImageSourceType ImageSourceType;

Now when i am using this line its give me error

    self.ImageSourceType=2;  / / assigning to 'ImageProcessType' from incompaitable with 'int'

尝试:

self.ImageSourceType = ImageSourceTypePhotoLibrary

To use numbers instead of names for enums, format the definition like so:

typedef enum{
    ImageSourceTypeCamera = 0,
    ImageSourceTypePhotoLibrary = 1,
    ImageSourceTypeNone = 2
  }
ImageSourceType;

self.ImageSourceType = 0; //ImageSourceTypeCamera
self.ImageSourceType = 1; //ImageSourceTypePhotoLibrary 
//etc...

if (self.ImageSourceType == 0) {
    //this is the same as (self.ImageSourceType == ImageSourceTypeCamera)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM