Can I use the Callback function for the Objective-C module?

Asked 1 years ago, Updated 1 years ago, 72 views

I would like to divide the functions of the iPhone app into several different modules.
Is it possible to use the Callback function for the Objective-C module?
For example, a module that receives GPS information receives location information and passes the location information to an external processing function.I want to separate it from GPS related modules such as external processing function names.
Example:

somefunction(){
  GPS modules (param1, function(position) {xxx});
}

For example, I would like to receive and process the position in Callback form using GPS module from external somefunction.

objective-c iphone

2022-09-30 16:55

1 Answers

("Module" has a special meaning in Apple's development environment, so I think it would be better to say it in a different way if possible.)

Objective-C can pass function pointers of type C, so callback functions can be passed in that form.
 Also, in recent Objective-C, block ("block structural language" is not a block, but an Objective-C term that is closer to a closure in another language), so that would be more like the code you indicated (JavaScript-style closure?).

Unless you have special circumstances such as "Most of them are written in C/C++ to call the C-language API," it is not recommended that you adopt the former C-language function pointer for future applications, so "You can use the block (of Objective-C)."

However, since you use object-oriented language, if you really want to do what you want to do, it might be more beautiful to involve classes and solve them in an object-oriented way.
 "For the time being, the answer to your question is ""yes"", but I just said that I can't say whether I really should adopt it or not without a little more information."


2022-09-30 16:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.