Re: Abstracting a group of commonly named Selectors


Sandor Szatmari
 

Gary, 

On Jul 20, 2020, at 15:53, Gary L. Wade <garywade@...> wrote:

You might want to consider using valueForUndefinedKey:

interesting… 

and parse it to know which value you care about, and then return the value through NSValue, which can encapsulate any value, although a number/enum mapping might be sufficient.

I’ll have to see if Returning an NSValue wrapped scalar translates to the scalar result on the other side when I call -getReturnValue: 

Thanks!

Sandor


On Jul 20, 2020, at 12:47 PM, Sandor Szatmari <admin.szatmari.net@...> wrote:

Alex,

Thanks for the idea.  I not sure how that helps me get the return value back to the original caller.   Am I missing your point?

Here’s more details, in pseudo code

// Controller class
SEL aSel
do

aSel = lookUpSel (i.e. parseXYZ)
NSInvocation *n = // make invocation with aSel
[n setTarget: ModelClass]
[n invoke]
Status s = success // I’m an optimist
[n getReturnValue:&s]

while more_sels

… Meanwhile…

// ModelClass
-(Status)parseXYZ
{
 // do the same thing for each parse method
 return [self parse:XYZ]
}

-(Status)parseRST
{
 // do the same thing for each parse method
 return [self parse:RST]
}

————

I want to change model class to do this
// remove parse SELs  i.e. remove parse[A-Z]{3} methods

// replace with something like
-doesNotRespondToSelector:(SEL)aSel
{
 NSString *sel = NSStringFromSelector(aSel)

 if ( sel has prefix ‘parse’ )
 {
   NSString *selCmd = [sel subStringFromIndex:5] // remove prefix ‘parse’. e.g.  ‘RST’ remains
   Status s = [self parse:selCmd]

   // how do I return ‘s’ to the original caller??? The Controller

 }
 else
   [super doesNotRespondToSelector:aSel]
}


Sandor

On Jul 20, 2020, at 13:27, Alex Zavatone via groups.io <zav@...> wrote:

Would it be possible to put them in an array or dictionary as NSStrings and use performSelector on one of them if it is present within the array or dict?

On Jul 20, 2020, at 12:11 PM, Sandor Szatmari <admin.szatmari.net@...> wrote:

I have a certain group of selectors that all follow a strict naming convention,

-(Status)parseXYZ
-(Status)parseRST

All have one line that does the same thing and return a scalar (enum) as a result.
Each method would do something XYZ or RST and return their status

There are about 200 of these… it’s quite annoying to maintain and look at this boiler plate interface.  It should not be necessary, I hope.

I would like to abstract them using something like:
 -doesNotRecognizeSelector:
 or
 -forwardInvocation:
 or
 By some other means, which I cannot conceive of…

The issue I don’t understand is, how would I return the scalar to the original caller once one of the methods has received the program flow.  Neither of these methods return anything.

Is what I want to do possible?
If so, what should I be looking at?

Sandor

Join cocoa@apple-dev.groups.io to automatically receive all group messages.