Rewriting compare for one NSNumber object

ksignorini

Registered
I have an NSNumber object called "initiative" that I need to use its compare method on.

Unfortunately, compare isn't doing what I thought it would so I want to rewrite it.

I have no idea how to write the first line of the method, though--the declaration!

I have the code I want to use within the method, but I don't know how to specify the method.

I tried this:

- (NSComparisonResult)compare:(NSNumber *)aNumber

but I know this isn't right because it doesn't say anything about WHICH NSNumber object to work with. I only want to use this for the object called "initiative" and no other NSNumber type objects.

Can this be done somehow?

Thanks,
Kent!
 
I figured out another way to do it. In the method that actually calls the compare method, I put my code instead. It works.

Still, if there is some other way to replace a method for a particular instance of an object I would sure like to know if it's possible.

Thanks,
Kent!
 
Hold on.

I'm tired.

I would just create a new class that extends from NSNumber and rewrite the compare method there. Then I would make my "initiative" object of type NewNSNumber.

Right?

Yeesh.

Kent!
 
Back
Top