Tuesday, 15 September 2015

ios - Dynamic Method Calls at Runtime -



ios - Dynamic Method Calls at Runtime -

my project going compiled bunch of legacy code (as >100 independent methods). different legacy methods going serve same purpose in project, differently. say, have same inputs , same outputs, complex calculations outputs, , calculations can vary between different methods. expect have phone call 1 of methods during given session, next session may need phone call different method. in project, when phone call 1 of methods, user have entered plenty info me able determine method call.

one way handle huge if block. have check against couple different conditions. each combination of conditions, phone call different 1 of legacy methods. problem approach bad readability point of view - actual if block end beingness 100s of lines long. imagine there performance issues many different else-if statements well.

what create look-up table, store name of method phone call (as string), , pair different conditions need check against. company trying shift policy towards using more look-up tables , fewer of huge if blocks.

is there way phone call method based on "method name" string i'm getting look-up table? if so, syntax doing that? or there other (better) ways handle haven't thought of? or huge if block more in line best practice?

nsinvocation might work needs. allows create method invocation selector , phone call later on. can utilize nsselectorfromstring create selector based on string looked up. there first-class tutorial on nsinvocation bookmarked while ago http://a-coding.com/making-nsinvocations/.

i'm not sure of other ways accomplish going can imagine approach getting hard debug , track, though never know until implement it.

i used nsinvocation 1 time set app 'demo' mode. created whole array of nssinvocations , whenever timer function fired grab next invocation , invoke it, allow app deed using it. anyways luck.

ios objective-c dynamic methods runtime

No comments:

Post a Comment