You need to prepend the static/class variable or function with the class name in which it is declared, even when in that same class.
In this case, you want to return AppDelegate.thedelegate!
and, as Martin R. points out, AppDelegate.thedelegate = self