NSError has a userInfo which is a dictionary. I would like to have a custom NSErrorUserInfoKey. I thought of a category for the NSError where I can define that key as a constant string. I know that I can't have properties in categories but is it possible and correct to add a constant to a category?
            Asked
            
        
        
            Active
            
        
            Viewed 51 times
        
    0
            
            
         
    
    
        h3dkandi
        
- 1,106
- 1
- 12
- 27
- 
                    The keys are strings aren't they, so see [this answer](https://stackoverflow.com/a/539191/299924). – trojanfoe Oct 08 '19 at 12:54
- 
                    Yes but is it ok to add them on a category? – h3dkandi Oct 08 '19 at 13:37
- 
                    1Does it have a `.h` and `.m` file? If so, then yes. – trojanfoe Oct 08 '19 at 13:38
- 
                    Thanks that would probably do then. – h3dkandi Oct 11 '19 at 12:25
1 Answers
0
            
            
        Yes we have option to add properties in category using
objc_setAssociatedObject 
and
objc_getAssociatedObject
objc_setAssociatedObject is used to set the value 
objc_getAssociatedObject is used to ge the value
About constants I would create another class for constant FOUNDATION_EXPORT and use it here. Something like CustomErrorUserInfoKeys.h 
 
    
    
        shinoy
        
- 146
- 1
- 8