I’m not sure if this is necessary but I UNMAPPED the eject function from the keyboard using the Gnome keyboard shortcuts gui (Click on Ubuntu Activities in top right, type keyboard and select the keyboard item: ‘View and Change Keyboard Shortcuts…’ In there you can find your eject key, about halfway down. You can click on this item then press backspace on the keyboard and click ‘Set’ to unmap the key.

Place the following .Xmodmap file in your home directory (the file consists of the single line):

keycode 169 = Delete

I use the location /home/gray/scripts/ for the script which will implement the Xmodmap. Here is the script:

#!/bin/bash
   touch /home/gray/scripts/touched
   sleep 2
   DISPLAY=":0"
   HOME=/home/gray
   XAUTHORITY=$HOME/.Xauthority
   export DISPLAY XAUTHORITY HOME
   /usr/bin/xmodmap /home/gray/.Xmodmap
   notify-send "Delete key mapped to eject key on Apple Wireless Keyboard"

Save this script as
/home/gray/scripts/appledeletekey.sh
set the script to executable:

chmod +x /home/gray/scripts/appledeletekey.sh

Create a udev rule as follows:

ACTION=="add", SUBSYSTEM=="input", SUBSYSTEMS=="input", ATTRS{name}=="Apple Wireless Keyboard", RUN+="/bin/systemctl start apple-delete-key.service"

The udev rule should be stored in the location:
/etc/udev/rules.d/98-apple-delete-key.rules
The file should be owned by root and have permissions 644

sudo chown root /etc/udev/rules.d/98-apple-delete-key.rules sudo chmod 644 /etc/udev/rules.d/98-apple-delete-key.rules

The file runs a systemd service which we need to create:

[Unit]
Description=appledeletekey
[Service]
Type=simple
ExecStart=/home/gray/scripts/appledeletekey.sh

Save this file as
/etc/systemd/services/apple-delete-key.service

The script does not seem fussy about permissions but it should be owned by root:

sudo chown root /etc/systemd/services/apple-delete-key.service

There should be no need to restart services, reboot your computer or anything else.

If you want to test this has all work, prior to rebooting here is how:
Open the battery hatch so the keyboard disconnects, wait a few seconds, close the battery hatch, hit the keyboard on button (on the right hand side of the battery hatch), and start hitting shift lock until I see the led responding (which means the keyboard is connected). Within two seconds you should have your eject key mapped to delete. Test it on some text.