iphone - Call back style -
I am writing an iPhone app that needs a very simple request response type non-HTTP or FTP networking at many places. is.
I have wrapped it all into a simpler class which is integrated with the run loop.
Simplified * Lookup = [[Simply Awesome] init]; [Deliverate Lookup Set: Self]; [Lookup doQueryToHost: queryServer Port: query query: queryString]; As you can see, the calling object sets itself as a representative. When the result is complete, the caller calls a method called on the results with the representative.
[Representative General Consequences: As a result of simplicity: self]; I am now in a situation where I have a user of the simple process that has two types of queries, so I need to expand the simple technique to support it.
I can think of
[lookup doQueryToHost: queryServer port: queryPort query: queryString selector: @ SEL];
The second doQueryString is passing a tag so that when the representative is told that he can query the tag, as if the simplicity is passed, then to find out What are the consequences?
[Lookup doQueryToHost: queryServer port: query query: queryString withTag: tag]; I am thinking that what is best with the perspective of coding style, firstly thought is easy, but tagging seems more to keep with the iPhone SDK and interface builder
One option that is commonly used in the code of the apple (for example, in UIControl) is both a target To provide the object and a selector. It works only when there is a single callback, and in that case a representative is more appropriate. (If there are many callbacks, you probably have to go with a representative and tag approach.)
If you go this route, then you remove the representative completely and instead a method Such as a signature:
doQueryToHost: (ID) query server port: (int) query query: (NSString *) queryString target: (ID) Goal action: (SEL) verb < / Code> Note that "action" in this case is " Preferred over Ynkrta "is. When done, the query will only call the selector on the target. This will allow your client to provide many selectors and many objectives; It can help to clean the code because you do not need to cover everything in the same representative object.
If you want to go through your tag route, then you call it "reference", which is the use of Apple (for example, in AddObserver: Capeth: Option: Reference).
Comments
Post a Comment