Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should NOT swizzle methods for this. This is deprecated behavior. This will affect ALL windows in your app not just the one you wanted to change. However, what you should do instead is to subclass NSWindow already and then change the class of that window at runtime. This can be done using this runtime function:</p> <pre><code>Class object_setClass(id object, Class cls) </code></pre> <p>Reference is here: <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/doc/uid/TP40001418-CH1g-SW12" rel="nofollow noreferrer">http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/doc/uid/TP40001418-CH1g-SW12</a></p> <p>Your code should then look like this:</p> <pre><code>object_setClass(theWindow, [MyWindowSubclass class]); </code></pre> <p>On problem you <em>might</em> experience is that window already being a subclass of NSWindow. If that's the case there are more complicated ways to achieve this. You can construct a class dynamically at runtime. Here's some more code. Given that window is the target window:</p> <pre><code>Class newWindowClass = objc_allocateClassPair([window class], "MyHackyWindowSubclass", 0); Method upMethod = class_getInstanceMethod(newWindowClass, @selector(keyUp:)); method_setImplementation(upMethod, new_NSWindow_keyUp_); object_setClass(window, newWindowClass); </code></pre> <p>I'm not totally sure this does not change the implementation of the superclass. The documentation is a bit unspecific about it. However, you should still try it. If it does not work, replace the second and third line by this one:</p> <pre><code>class_replaceMethod(newWindowClass, @selector(keyUp:), new_NSWindow_keyUp_, "v@:@"); </code></pre> <p>In any case you need to define the new Method implementation. It could look like that (partially by KennyTM):</p> <pre><code>void new_NSWindow_keyUp_(NSWindow* self, SEL _cmd, NSEvent* evt) { [super keyUp: evt]; ... // do your changes } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload