0

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?

h3dkandi
  • 1,106
  • 1
  • 12
  • 27

1 Answers1

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