Saving Callbacks in a Dictionary (Objective-C for iPhone)

I am trying to store callbacks in a dictionary.

  • I cannot use blocks because the iPhone does not support this (unless you use plblocks).
  • I tried to use functions, but apparently NSMutableDictionary does not allow these pointers (wants identifier)
  • I tried using class methods, but I could not find a way to get a pointer to these
  • I could try using functions with the C ++ stl hashmap (if supported in Objective-C ++), but apparently this could slow down compilation time.
  • I could try to save both the class and the selector, but that seems pretty messy.

What would be the best way to do this?

+3
source share
4 answers

, , NSValue. NSValue .

:

[myDict setObject:[NSValue valueWithPointer:functionName] forKey:myKey];

:

NSValue* funcVal=(NSValue*) [myDict objectForKey:myKey];
returnType* (*func)()=[funcVal pointerValue];
+4

NSInvocation.

NSInvocation - Objective-C , , . NSInvocation , NSTimer .

+7

, , ?

0

++, .mm. , ++.

0

Source: https://habr.com/ru/post/1729159/


All Articles