Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Another block challenge
-
Sorry to be so hopeless, but now I have this signature:
(void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString *result))completionHandler;
Thus I should call the block with a pointer to an NSString as an argument. How do I get one from the Python string I have at hand, and what should I have as the ctypes argument - probably c_void_p?
-
NSString is an object, so would be c_void_p. if you have a python string, you can use ns( your_string ) to convert to an NSString. Actually, the ObjCBlock's call method might already be calling ns() on each argument to do all the the conversions for you (at least, ObjCMethod does), but I'm not 100% sure. ns() handles many common types.
To get a python string from NSString, iirc str(your_ns_string_objc_instance) works.
-
btw, despite the seemingly extra pointer, you would pass the output of ns() directly -- that creates the ibject, the. the ObjCInstance's from_param passes the .objc_ptr.
-
@JonB, thanks, that was too easy!
blk.invoke(_completion_handler, ns(python_string))