I've been trying to replicate the usual way of doing this in Objective-C in Swift for a new swift app I'm playing around with.
How to do this in Objective-C is well documented, you get the shared apple event manager and call setEventHandler
method to register a function as the handler for the event class kInternetEventClass
with the event id kAEGetURL
.
So in swift I'm trying to do the same thing with this code added to the template AppDelegate.swift inside a brand new project:
func applicationWillFinishLaunching(aNotification: NSNotification?) {
var appleEventManager:NSAppleEventManager = NSAppleEventManager.sharedAppleEventManager()
appleEventManager.setEventHandler(self, andSelector: "handleGetURLEvent:withReplyEvent:", forEventClass: kInternetEventClass, andEventID: kAEGetURL)
}
func handleGetURLEvent(event: NSAppleEventDescriptor?, replyEvent: NSAppleEventDescriptor?) {
println("yay");
}
As far as I can tell this is just a syntax conversion of the standard Objective-c call. But I get a type error for both the forEventClass
and andEventId
arguments to the setEventHandler
method:
'NSNumber' is not a subtype of 'AEEventClass'
for the forEventClass
argument
and:
'NSNumber' is not a subtype of 'AEEventId'
for the andEventID
argument
I'm not sure what I'm doing wrong at this stage as both kInternetEventClass
and kAEGetURL
are constants defined by apple... Surely I'm not required to convert their NSNumber
type to their respective required types? And if I am I can't work out how.