objective c - How to use performSelector:withObject:afterDelay: on a method with multiple arguments -


Assume that I have a method with this signature:

  - (void ) Plotpoli: (Polygon *) Poly withColor: (UIColor *) Color AndFill: (BOOL) Filled;  

How do I get that UIColor and BOOL as well as polygon ?

Should I wrap them in the NSArray and pull them out of the method called? This will mean that I have to change the method, okay?

Is there any more attractive way to do this?

I answered a fairly common question a few weeks ago. Answer the answer given below for this question.

In general, I want to avoid NSInvocation for this type of work. It is a maintenance headache and, in particular, creates difficulty in refactoring in the future. First of all, this method was given:

  - (zero) plotPoly :( polygon *) Poly withColor: (UIColor *) Color AndFill: (BOOL) filled;  

It is usually declared:

  - (zero) plot policy: (polygon *) a poli color: (UIColor *) aColor filled : (BOOL) filledFlag;  

This naming conveys a few more closely the conventions.

Now, what I will do is actually capture the arguments in a simple class that provides -

PolyPlotter.h:

  @interface PolyPlotter: NSObject {polygon * poly; UIColor * color; BOOL Fill; } + Plaster with poly: (polygon *) one color: (UIColor *) One color filled: (BOOL) Filled flag; - (zero) conspiracy; @end  

PolyPlotter.m:

  @interface PolyPlotter () @property polygon * shift; @ Property UIColor * color; @ Property BOOL is full; @end @implementation PolyPlotter @ shift, color, synthesis for synthesis; + Plotters with poly: (polygon *) One color: (UIColor *) One color filled: (BOOL) Filled flag; {Polyplor * polygonplatform = [polyplatter new]; Polygon plotters yellow = a policy; Polygon planner Color = a color; Polygon plotter.fill = bufflag; Return [Polygon Plus Autocorrect]; } - (zero) plot; {// ... Here's your plot ...} @end  

The usage is straightforward, just make an example of PolygonPlotter and it's delay or at the main thread or whatever, the selector < Ask for the code> plot .

Looking at the question, I suspect that you may need a little more context at the time of illustration? If so, you can pass that information as argument from -plot , say, by declaring the method:

  - (zero) Plot: (UIView *) aViewToPlotIn;  

Or something like that.

Like I said, there is a bit more code, but more flexible than the NSINW conversion pattern and again. For example, you can easily create polygon plotters that can be stored easily.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -