Adding Properties to NKIssue?

  • Hi,

    It is possible to add my own properties to the NKIssue Class? I know
    it's possible in Objective-C but is it advisable? I was thinking of
    something like this:

    @interface NKIssue (MyIssue)

    @property (nonatomic,retain)                MutableDictionary*
    somethingSpecificToMyApp;

    @end

    Thanks in advance
    Dave
  • On Jul 2, 2012, at 12:31 PM, Dave wrote:

    > Hi,
    >
    > It is possible to add my own properties to the NKIssue Class? I know it's possible in Objective-C but is it advisable? I was thinking of something like this:

    Yes and It Depends. You can't use @synthesize or add ivars in a category, so you'll have to write the corresponding accessor method(s) yourself.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • On 2 Jul 2012, at 22:27, Nick Zitzmann wrote:

    >
    > On Jul 2, 2012, at 12:31 PM, Dave wrote:
    >
    >> Hi,
    >>
    >> It is possible to add my own properties to the NKIssue Class? I
    >> know it's possible in Objective-C but is it advisable? I was
    >> thinking of something like this:
    >
    > Yes and It Depends. You can't use @synthesize or add ivars in a
    > category, so you'll have to write the corresponding accessor method
    > (s) yourself.
    >
    > Nick Zitzmann

    Hi,

    Thanks for your help, I'm not sure I get what you mean?

    Given that I have defined a property:

    @interface NKIssue (MyIssue)

    @property (nonatomic,retain)    NSMutableDictionary*
    somethingSpecificToMyApp;

    @end

    I could then write the getter/setter:

    -(void) setSomethingSpecificToMyApp:(NSMutableDictionary*) theDict
    {
    }

    But where do I store the Dictionary? I can't add an iVar to the
    NKIssue as this is not possible in Objective-C AFAIK.

    All the Best
    Dave
  • On 4 Jul 2012, at 3:31 PM, Dave wrote:

    > But where do I store the Dictionary? I can't add an iVar to the NKIssue as this is not possible in Objective-C AFAIK.

    Do you really need to extend NKIssue instead of making a class of your own that has an NKIssue and an NSMutableDictionary?

    — F
  • Hi,

    That's more or less what we have at the moment and I think it's just
    fine and probably better in the long run. However someone else thinks
    it would be a better idea to do it my extending NKIssue if it is
    possible, but it seems it's not, since there is no way I can see of
    actually storing the property value anywhere, since you can't add
    iVar's.

    Cheers
    Dave

    On 4 Jul 2012, at 21:40, Fritz Anderson wrote:

    > On 4 Jul 2012, at 3:31 PM, Dave wrote:
    >
    >> But where do I store the Dictionary? I can't add an iVar to the
    >> NKIssue as this is not possible in Objective-C AFAIK.
    >
    > Do you really need to extend NKIssue instead of making a class of
    > your own that has an NKIssue and an NSMutableDictionary?
    >
    > — F
    >
  • On 7/4/12 2:27 PM, Dave wrote:
    > Hi,
    >
    > That's more or less what we have at the moment and I think it's just
    > fine and probably better in the long run. However someone else thinks it
    > would be a better idea to do it my extending NKIssue if it is possible,
    > but it seems it's not, since there is no way I can see of actually
    > storing the property value anywhere, since you can't add iVar's.

    A workaround in situations where you need to add storage is to use
    associated objects.

    See
    http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/obje
    ctivec/Chapters/ocAssociativeReferences.html

    and the Objective-C run-time reference for details.

    It's really quite easy, and since NKIssue is only in iOS 5 and newer you
    don't have any backward compatibility issues.

    Note that you will need to import <objc/runtime.h> for the functions.

    --
    Conrad Shultz

    Synthetiq Solutions
    www.synthetiqsolutions.com
  • On Jul 4, 2012, at 8:30 PM, Conrad Shultz wrote:

    > On 7/4/12 2:27 PM, Dave wrote:
    >> Hi,
    >>
    >> That's more or less what we have at the moment and I think it's just
    >> fine and probably better in the long run. However someone else thinks it
    >> would be a better idea to do it my extending NKIssue if it is possible,
    >> but it seems it's not, since there is no way I can see of actually
    >> storing the property value anywhere, since you can't add iVar's.
    >
    > A workaround in situations where you need to add storage is to use
    > associated objects.
    >
    > See
    > http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/obje
    ctivec/Chapters/ocAssociativeReferences.html

    > and the Objective-C run-time reference for details.
    >
    > It's really quite easy, and since NKIssue is only in iOS 5 and newer you
    > don't have any backward compatibility issues.
    >
    > Note that you will need to import <objc/runtime.h> for the functions.

    While that’s true, it’s a much less elegant solution than just using an object, as you are doing.

    Charles
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today