Re: Abstracting a group of commonly named Selectors


Sandor Szatmari
 

Alex,

On Jul 20, 2020, at 15:51, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

Well, I’m guessing here, but can’t you construct the method and use a perform selector, get the result and return it?
I am proposing letting the runtime handle the fact the object does not respond to the selector. So, under this assumption I am inside one of two methods:

-doesNotRespondToSelector: or -forwardInvocation:

Both of which have a void return. So I don’t see how I can return data to the original caller… I’m not sure there’s a way to do it, but was hoping to be unaware of how to use these methods, or an alternate means of generically responding to selectors.


It seems like you are making methods, performing them, then need to perform methods within that, right? Can’t you simplify that?
Unfortunately, this is code (The controller) at the heart of a framework and many classes depend on it. I can’t justify changing that code. But I can consider writing a new model (one with lot’s of redundant selectors) in an new way.

Thanks for your ideas!

Sandor

Or somehow define what becomes parsed in the method?

It seems like this can be simplified.

On Jul 20, 2020, at 2:47 PM, Sandor Szatmari <admin.szatmari.net@gmail.com> 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=mac.com@groups.io> 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@gmail.com> 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.