typedef NS_ENUM: passing an NSDictionary of custom properties to method

300 views Asked by At

I've created a macro like this, and a definition:

#define CustomImageOptions NSDictionary
typedef NS_ENUM(NSInteger, CustomImageOption) {
    CustomImageOptionResize, // CGSize
    CustomImageOptionQuality, // CGFloat
    CustomImageOptionType // NSString (JPEG or PNG)
};

I've got a method like this:

- (UIImage*)imageModifiedWithOptions:(CustomImageOptions*)options;

where i'd like to pass a dictionary of options to it like so (pseudo code):

[self imageModifiedWithOptions:@{CustomImageOptionResize: CGSizeMake(10, 20), CustomImageQuality: 0.9}];

It won't compile, presumably because my macro is of type NSInteger, which is not enumerable as a key for NSDictionary.

How can I implement this so I can pass an NSDictionary of options to my method?

1

There are 1 answers

1
Mobile Ben On BEST ANSWER

Do it this way:

[self imageModifiedWithOptions:@{@(CustomImageOptionResize): CGSizeMake(10, 20), @(CustomImageQuality): 0.9}];

They need to be converted to NSNumbers first.