# Objc ffi: implement \`windowWillClose:\`

**URL:** <https://racket.discourse.group/t/objc-ffi-implement-windowwillclose/549>\
**Category:** Questions & Answers\
**Created:** [January 11, 2022, 1:21pm UTC](https://racket.discourse.group/t/objc-ffi-implement-windowwillclose/549 "2022-01-11T13:21:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dannypsnl](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dannypsnl/32/917_2.png) [@dannypsnl](https://racket.discourse.group/u/dannypsnl)\
**Post date:** [January 11, 2022, 1:21pm UTC](https://racket.discourse.group/t/objc-ffi-implement-windowwillclose/549/1 "2022-01-11T13:21:03Z")

</div>

The code is like:

```scheme
(define-objc-class MyView NSView
  ()
  (- _void (windowWillClose: [(_cpointer 'NSNotification) notification])
     (tell app terminate: #:type _id self)))

```

the corresponding code in Objective-C correct handle signal like Ctrl+C, but racket version cannot work same.

Full code:

- racket: [cocoa/simple-view.rkt at develop · dannypsnl/cocoa · GitHub](https://github.com/dannypsnl/cocoa/blob/develop/experiment/simple-view.rkt)
- objc: [cocoa/main.m at develop · dannypsnl/cocoa · GitHub](https://github.com/dannypsnl/cocoa/blob/develop/objc/main.m)

---

<div class="post-metadata">

**Author:** ![mflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/mflatt/32/6_2.png) [@mflatt](https://racket.discourse.group/u/mflatt)\
**Post date:** [January 12, 2022, 1:55pm UTC](https://racket.discourse.group/t/objc-ffi-implement-windowwillclose/549/2 "2022-01-12T13:55:59Z")

</div>

I'm not sure I follow, but I think you're seeing that Racket installs a `SIGINT` handler to convert Ctl-C into a Racket `exn:break` exception. On macOS, you could remove that signal handler with

```scheme
((get-ffi-obj 'signal #f (_fun _int _intptr -> _void)) 2 0)

```

and then Ctl-C terminates "simple-view.rkt".

But it's not about `windowWillClose:` in that case; the default Ctl-C treatment exits immediately without calling object methods. An immediate exit on Ctl-C also seems to happen when I run "main.m", so I may be missing something about your setup.

---

<div class="post-metadata">

**Author:** ![dannypsnl](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dannypsnl/32/917_2.png) [@dannypsnl](https://racket.discourse.group/u/dannypsnl)\
**Post date:** [January 12, 2022, 2:12pm UTC](https://racket.discourse.group/t/objc-ffi-implement-windowwillclose/549/3 "2022-01-12T14:12:25Z")

</div>

Interesting! so more like racket does something and stop me, not objc doing something here. But I still have a problem that

```scheme
(- _void (drawRect: [_NSRect rect])
  ...)

```

didn't work. Maybe just keep tracking in this topic? Since they're about implement objc method

---

<div class="post-metadata">

**Author:** ![mflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/mflatt/32/6_2.png) [@mflatt](https://racket.discourse.group/u/mflatt)\
**Post date:** [January 12, 2022, 2:28pm UTC](https://racket.discourse.group/t/objc-ffi-implement-windowwillclose/549/4 "2022-01-12T14:28:19Z")

</div>

Your drawing code has `(in-range (* 2 pi) (/ (* 2 pi) n))` where you meant `(in-range 0 (* 2 pi) (/ (* 2 pi) n))`. Also, you'll need to specify `#:type _NSPoint` for each argument to `strokeLineFromPoint:toPoint:`.

---

<div class="post-metadata">

**Author:** ![dannypsnl](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dannypsnl/32/917_2.png) [@dannypsnl](https://racket.discourse.group/u/dannypsnl)\
**Post date:** [January 12, 2022, 2:43pm UTC](https://racket.discourse.group/t/objc-ffi-implement-windowwillclose/549/5 "2022-01-12T14:43:45Z")

</div>

oops, another stupid error made by myself. Thanks a lot! You save my day.
