Save typedef enum objects in NSUserDefaults
enums, objective-c
Solution
`NSUserDefaults` stored objects not C data types.
Not tried this but you might be able to get away with just the following change:
[[NSUserDefaults standardUserDefaults] setObject:@(ViewType) forKey:@"ProductViewType"];
The `@()` notation is short-hand for `[NSNumber numberWithInt:viewType]`.
Problem
I have written the following code: ``` typedef enum { kProductList, kProductGrid, kProductSingleView } ProductViewType; ProductViewType ViewType; ``` In my view change method, I am changing the ViewType. When the app closes I want to save the last ViewType in a UserDefauls, so that when first time load, I can check users last ViewType and set it to default. I have written the following code: ``` [[NSUserDefaults standardUserDefaults] setObject:ViewType forKey:@"ProductViewType"]; ``` But XCode shows an warning: incompatible pointer to integer conversion. any solutions ? thanks.