iPhone SDK | Run a method from a separate class
26/03/2010
I often need to run code from a method which is in an alternative class (.m file if you will).
This is done with the following:
//Alert if in offline mode
deStockLookup *deStock = [[deStockLookup alloc] init];
gotInternet = [deStock checkInternet];
In This case, the output of the method checkInternet in the class deStockLookup is assigned to the variable gotInternet.
A simpler code snippet is running a method which takes no input or output. This would be done in the following:
deStockLookup *deStock = [[deStockLookup alloc] init];
[deStock checkInternet];
Notice that it is quite similar to how to call a method within the same class, which is done by:
[self localMethodName];
I use this code in almost every project and its one of those tricky little things I just needed on my site!
No comments yet.