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?
Do it this way:
[self imageModifiedWithOptions:@{@(CustomImageOptionResize): CGSizeMake(10, 20), @(CustomImageQuality): 0.9}];
They need to be converted to NSNumber
s first.